Marshmallow FINE and COARSE location permission

Robin Dijkhof picture Robin Dijkhof · Nov 18, 2015 · Viewed 19.4k times · Source

I'm trying to access ACCESS_FINE_LOCATION and if it cannot be found access ACCESS_COARSE_LOCATION. So I request for those 2 permission, but they give me the same dialog asking for location permission. I know those are both in the same group but Google says:

Note: Your app still needs to explicitly request every permission it needs, even if the user has already granted another permission in the same group. In addition, the grouping of permissions into groups may change in future Android releases. Your code should not rely on the assumption that particular permissions are or are not in the same group.

This means I ask for those 2 permissions within a second, which results in 2 dialog in a row. THis does not seem very user friendly to me. Is there a better way?

Answer

Rajesh picture Rajesh · Nov 19, 2015

You do not need ACCESS_COARSE_LOCATION permission when you define ACCESS_FINE_LOCATION permission.

From Android Documentation:

Requesting User Permissions

In order to receive location updates from NETWORK_PROVIDER or GPS_PROVIDER, you must request user permission by declaring either the ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission, respectively, in your Android manifest file. For example:

<manifest>
      <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
       .......
</manifest>

Without these permissions, your application will fail at runtime when requesting location updates.

Note: If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then you need to request only the ACCESS_FINE_LOCATION permission, because it includes permission for both providers. (Permission for ACCESS_COARSE_LOCATION includes permission only for NETWORK_PROVIDER.)

Please look at https://developer.android.com/guide/topics/location/strategies.html