Android M Google API's to use Google Maps and other permissions

1.2k views Asked by At

I have Android M set up for my project and could build fine. However, When i launch the app, i see the following error and app doesn't launch:

<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)

I have provided all these permissions access_fine_location, network_state, internet and access_coarse_location in my manifest file as "PROTECTED_NORMAL" So that they are available at install time.

I also noticed that Google API's were missing from Android M preview and may be thats causing the issue?? not sure though. Wondering if anyone came across the same issue and a possible solution?

part of manifest file:

 <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>

Thanks!!

1

There are 1 answers

2
CommonsWare On BEST ANSWER

I have provided all these permissions access_fine_location, network_state, internet and access_coarse_location in my manifest file as "PROTECTED_NORMAL" So that they are available at install time.

No. Those permissions are defined by the platform, not you. You cannot redefine them to have lower protection levels, and the LOCATION permissions are dangerous. And, as the M Developer Preview documentation states, those are permissions that you need to request at runtime.

a possible solution?

Request the location permissions from the user before attempting to use the map. Note that I have not tried maps on the M Developer Preview yet, so it may be that this is not supported at all right now.