我为我的项目设置了 Android M,并且可以正常构建。但是,当我启动应用程序时,我看到以下错误并且应用程序无法启动:
<06-23 11:53:24.833 32416 32416 W System.err: java.lang.RuntimeException: **Unable to create application xxxxx: java.lang.SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission.**
06-23 11:53:24.833 32416 32416 W System.err: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4697)
06-23 11:53:24.833 32416 32416 W System.err: at android.app.ActivityThread.-wrap1(ActivityThread.java)
06-23 11:53:24.833 32416 32416 W System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1404)
06-23 11:53:24.833 32416 32416 W System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
06-23 11:53:24.833 32416 32416 W System.err: at android.os.Looper.loop(Looper.java:148)
06-23 11:53:24.833 32416 32416 W System.err: at android.app.ActivityThread.main(ActivityThread.java:5401)
06-23 11:53:24.833 32416 32416 W System.err: at java.lang.reflect.Method.invoke(Native Method)
06-23 11:53:24.833 32416 32416 W System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:725)
06-23 11:53:24.833 32416 32416 W System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:615)
06-23 11:53:24.833 32416 32416 W System.err: Caused by: **java.lang.SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission**.
06-23 11:53:24.833 32416 32416 W System.err: at android.os.Parcel.readException(Parcel.java:1599)
06-23 11:53:24.833 32416 32416 W System.err: at android.os.Parcel.readException(Parcel.java:1552)
06-23 11:53:24.833 32416 32416 W System.err: at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:598)
06-23 11:53:24.834 32416 32416 W System.err: at android.location.LocationManager.requestLocationUpdates(LocationManager.java:880)
06-23 11:53:24.834 32416 32416 W System.err: at android.location.LocationManager.requestLocationUpdates(LocationManager.java:464)
我在清单文件中将所有这些权限 access_fine_location、network_state、internet 和 access_coarse_location 提供为“PROTECTED_NORMAL”,以便它们在安装时可用。
我还注意到 Android M 预览版中缺少 Google API,这可能是导致问题的原因?不过不确定。想知道是否有人遇到过同样的问题和可能的解决方案?
清单文件的一部分:
<uses-sdk
android:minSdkVersion ="MNC"
android:targetSdkVersion ="MNC" />
<permission
android:name="android.permission.ACCESS_NETWORK_STATE"
android:protectionLevel="normal" />
<permission
android:name="android.permission.ACCESS_FINE_LOCATION"
android:protectionLevel="normal" />
<permission
android:name="android.permission.ACCESS_COARSE_LOCATION"
android:protectionLevel="normal" />
<permission
android:name="android.permission.INTERNET"
android:protectionLevel="normal" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<application>
<uses-library android:name="com.google.android.maps" />
**activity declarations**
</application>
谢谢!!