LocationManager exception
I'm trying to make LocationManager work and get weird security exception. When I run code:
this.lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
this.lm.setTestProviderStatus(LocationManager.GPS_PROVIDER, LocationProvider.AVAILABLE, null, System.currentTimeMillis());
I get following exception:
Caused by: java.lang.SecurityException: Requires ACCESS_MOCK_LOCATION permission
at android.os.Parcel.readException(Parcel.java:1247)
at android.os.Parcel.readException(Parcel.java:1235)
at android.location.ILocationManager$Stub$Proxy.setTestProviderStatus(ILocationManager.java:9开发者_如何学Python81)
at android.location.LocationManager.setTestProviderStatus(LocationManager.java:1107)
And I have following in manifest file:
<application android:label="IDATT" android:icon="@drawable/icon" android:debuggable="true">
<uses-permission name="android.permission.ACCESS_MOCK_LOCATION"/>
<uses-permission name="android.permission.ACCESS_LOCATION"/>
<uses-permission name="android.permission.ACCESS_GPS"/>
<uses-permission name="android.permission.ACCESS_FINE_LOCATION"/>
<activity android:name=".MainActivity" android:screenOrientation="portrait">
<uses-permission .../>
goes outside the <application .../>
tag.
See Structure of the Manifest File.
On your device, go to Settings -> Applications -> Development and make sure that "Allow Mock Location" is checked.
精彩评论