我试图设置我的模拟位置但是,我收到以下错误(提供商' gps'未知)并且不确定出现了什么问题?
我已经在manifest.xml中声明了所有权限以及所有参数。
模拟定位方法
//Initiates the method to set the phones location
private void setMockLocation() {
mLocationManager.removeTestProvider(LocationManager.GPS_PROVIDER);
mLocationManager.addTestProvider
(
LocationManager.GPS_PROVIDER,
"requiresNetwork" == "",
"requiresSatellite" == "",
"requiresCell" == "",
"hasMonetaryCost" == "",
"supportsAltitude" == "",
"supportsSpeed" == "",
"supportsBearing" == "",
android.location.Criteria.POWER_LOW,
android.location.Criteria.ACCURACY_FINE
);
Location newLocation = new Location(LocationManager.GPS_PROVIDER);
newLocation.setLatitude (32.4276462);
newLocation.setLongitude(-23.5509257);
newLocation.setAccuracy(500);
mLocationManager.setTestProviderEnabled
(
LocationManager.GPS_PROVIDER,
true
);
mLocationManager.setTestProviderStatus
(
LocationManager.GPS_PROVIDER,
LocationProvider.AVAILABLE,
null,
System.currentTimeMillis()
);
mLocationManager.setTestProviderLocation
(
LocationManager.GPS_PROVIDER,
newLocation
);
}
错误消息
5-09 16:28:45.577 9070-9070/com.example.ankhit.saveme E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.IllegalArgumentException: Provider "gps" unknown at android.os.Parcel.readException(Parcel.java:1429) at android.os.Parcel.readException(Parcel.java:1379) at android.location.ILocationManager$Stub$Proxy.removeTestProvider(ILocationManager.java:956) at android.location.LocationManager.removeTestProvider(LocationManager.java:1194) at com.example.ankhit.saveme.UserLocation.setMockLocation(UserLocation.java:215) at com.example.ankhit.saveme.UserLocation.access$000(UserLocation.java:41) at com.example.ankhit.saveme.UserLocation$4.onClick(UserLocation.java:173) at android.view.View.performClick(View.java:4439) at android.view.View$PerformClick.run(View.java:18398) at android.os.Handler.handleCallback(Handler.java:725) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:176) at android.app.ActivityThread.main(ActivityThread.java:5299) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) at dalvik.system.NativeStart.main(Native Method)
有什么想法吗?