LocationManager exception

匿名 (未验证) 提交于 2019-12-03 01:40:02

问题:

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:981)         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"> 

回答1:

<uses-permission .../> goes outside the <application .../> tag.

See Structure of the Manifest File.



回答2:

On your device, go to Settings -> Applications -> Development and make sure that "Allow Mock Location" is checked.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!