I am trying to run the code below to get the user location (altitude/latitude/longitude) but it's not working. On logCat I am getting the following error messages:
07-15 02:59:47.575: ERROR/vold(26): Error opening switch name path '/sys/class/switch/test' (No such file or directory)
07-15 02:59:47.575: ERROR/vold(26): Error bootstrapping switch '/sys/class/switch/test' (No such file or directory)
07-15 02:59:47.575: ERROR/vold(26): Error opening switch name path '/sys/class/switch/test2' (No such file or directory)
07-15 02:59:47.575: ERROR/vold(26): Error bootstrapping switch '/sys/class/switch/test2' (No such file or directory)
07-15 03:00:15.075: ERROR/BatteryService(60): usbOnlinePath not found
07-15 03:00:15.075: ERROR/BatteryService(60): batteryVoltagePath not found
07-15 03:00:15.075: ERROR/BatteryService(60): batteryTemperaturePath not found
07-15 03:00:15.134: ERROR/SurfaceFlinger(60): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
07-15 03:00:25.965: ERROR/EventHub(60): could not get driver version for /dev/input/mouse0, Not a typewriter
07-15 03:00:25.975: ERROR/EventHub(60): could not get driver version for /dev/input/mice, Not a typewriter
07-15 03:00:26.404: ERROR/System(60): Failure starting core service
07-15 03:00:26.404: ERROR/System(60): java.lang.SecurityException
07-15 03:00:26.404: ERROR/System(60): at android.os.BinderProxy.transact(Native Method) 07-15 03:00:26.404: ERROR/System(60): at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)
07-15 03:00:26.404: ERROR/System(60): at android.os.ServiceManager.addService(ServiceManager.java:72)
07-15 03:00:26.404: ERROR/System(60): at com.android.server.ServerThread.run(SystemServer.java:176)
07-15 03:00:26.414: ERROR/AndroidRuntime(60): Crash logging skipped, no checkin service
07-15 03:00:49.123: ERROR/vold(26): Cannot start volume '/sdcard' (volume is not bound)
07-15 03:00:51.363: ERROR/MediaPlayerService(30): Couldn't open fd for content://settings/system/notification_sound
07-15 03:00:51.443: ERROR/MediaPlayer(60): Unable to to create media player
07-15 03:00:54.393: ERROR/ActivityThread(106): Failed to find provider info for android.server.checkin
07-15 03:00:58.313: ERROR/ActivityThread(106): Failed to find provider info for android.server.checkin
07-15 03:00:58.533: ERROR/ActivityThread(106): Failed to find provider info for android.server.checkin
07-15 03:01:04.994: ERROR/AndroidRuntime(131): ERROR: thread attach failed
07-15 03:01:19.295: ERROR/AndroidRuntime(174): ERROR: thread attach failed
07-15 03:01:26.345: ERROR/ActivityThread(60): Failed to find provider info for com.google.settings
07-15 03:01:26.355: ERROR/ActivityThread(60): Failed to find provider info for com.google.settings
07-15 03:01:27.236: ERROR/ActivityThread(214): Failed to find provider info for com.google.settings
07-15 03:01:27.256: ERROR/ActivityThread(214): Failed to find provider info for com.google.settings
07-15 03:01:27.375: ERROR/ActivityThread(214): Failed to find provider info for com.google.settings
07-15 03:01:48.195: ERROR/gralloc(60): [unregister] handle 0x384650 still locked (state=40000001)
07-15 03:01:57.138: ERROR/ActivityThread(60): Failed to find provider info for android.server.checkin
07-15 03:01:57.346: ERROR/gralloc(60): [unregister] handle 0x11ee50 still locked (state=40000001)
What could be wrong/missing?
Manifest:
<?xml version="1.0" encoding="u开发者_运维问答tf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.learn2develop.Location"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<uses-library android:name="com.google.android.maps" />
<!-- uses-library android:name="android.location" /-->
<!--fim insercao -->
<activity android:name=".AppStart"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES" />
</manifest>
Java Code:
package net.learn2develop.Location;
import java.util.ArrayList;
import java.util.List;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
public class AppStart extends MapActivity {
private LocationManager myLocationManager;
private LocationListener myLocationListener;
private MapView myMapView;
private MapController myMapController;
private List<Overlay> mapOverlays;
//Button gpsON;
/** Called when the activity is first created. */
private void CenterLocation(GeoPoint centerGeoPoint) {
mapOverlays = myMapView.getOverlays();
myMapController.animateTo(centerGeoPoint);
Drawable drawable = this.getResources().getDrawable(
R.drawable.icon);
HelloItemizedOverlay itemizedOverlay = new HelloItemizedOverlay(
drawable, this);
//OverlayItem overlayitem = new OverlayItem(centerGeoPoint);
//itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//gpsON = (Button) findViewById(R.id.mapView);
myMapView = (MapView) findViewById(R.id.mapView);
myMapView.setSatellite(true);
myMapView.setBuiltInZoomControls(true);
// Set satellite view
myMapController = myMapView.getController();
myMapController.setZoom(15);
// Fixed Zoom Level
mapOverlays = myMapView.getOverlays();
myLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
myLocationListener = new MyLocationListener();
myLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
0, 0, myLocationListener);
//myLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
// 0, 0, myLocationListener);
// Get the current location in start-up
GeoPoint initGeoPoint = new GeoPoint((int) (myLocationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER)
.getLatitude() * 1E6), (int) (myLocationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER)
.getLongitude() * 1E6));
CenterLocation(initGeoPoint);
}
private class MyLocationListener implements LocationListener {
public void onLocationChanged(Location argLocation) {
// TODO Auto-generated method stub
GeoPoint myGeoPoint = new GeoPoint(
(int) (argLocation.getLatitude() * 1E6),
(int) (argLocation.getLongitude() * 1E6));
CenterLocation(myGeoPoint);
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
public class HelloItemizedOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private Context mContext;
public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
super(boundCenterBottom(defaultMarker));
mContext = context;
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
@Override
public int size() {
return mOverlays.size();
}
@Override
protected boolean onTap(int index) {
OverlayItem item = mOverlays.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
return true;
}
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
};
}
tnx in advance
精彩评论