When should I use ACCESS_COARSE_LOCATION permission?
K

5

99

I am building an Android app that will track the user's geolocation and draw their route on a map.

I am using the Google Play Services location API, as described here.

It is intuitive that my application requires the ACCESS_FINE_LOCATION permission, which I put in the manifest:

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

Do I also need the ACCESS_COARSE_LOCATION permission? What's the use case where I need the coarse location?

Kordofanian answered 8/3, 2016 at 14:9 Comment(5)
ACCESS_COARSE_LOCATION includes permission only for NETWORK_PROVIDER Not GPSZion
@IntelliJAmiya: I am pretty sure you can still use the GPS_PROVIDER even with only coarse permission, but the data will be fuzzed to introduce a measure of inaccuracy, for privacy.Cutpurse
@Cutpurse Sir . Thanks for your information .Zion
@IntelliJAmiya: Actually, I may have been mistaken. The docs claim that you can only use NETWORK_PROVIDER with ACCESS_COARSE_LOCATION. Some of the AOSP code suggests that too, while other portions of the AOSP code suggest that they "fudge" the data as I thought was the case. Hence, to be safe, it's probably best to assume that you cannot get locations from GPS_PROVIDER with only ACCESS_COARSE_LOCATION, though it's worth some testing.Cutpurse
@IntelliJAmiya: I just ran a test, and on Android 6.0 at least, you need ACCESS_FINE_LOCATION to use GPS_PROVIDER. You'll crash with a SecurityException otherwise.Cutpurse
C
112

Do I also need the ACCESS_COARSE_LOCATION permission?

No.

What's the use case where I need the coarse location?

If you do not ask for ACCESS_FINE_LOCATION, but you need location data, and you are willing for that data to be fuzzy (say, up to around a city block from the user's position). In the case of LocationManager, you can only use the NETWORK_PROVIDER; in the case of the Play Services fused location provider, they should handle this internally.

Once upon a time, long long ago, users were told at install time whether the app wanted coarse or fine location access. Users might accept apps that wanted coarse access but reject apps that wanted fine access.

Since the UI for this has changed, and users would have a fair bit of difficulty determining whether an app wants coarse or fine location permission, I suspect that most developers just ask for fine location permission. That being said, if you know that your app does not need that level of accuracy (e.g., you want the location for a weather forecast), asking for coarse location permission is a nice "tip of the hat" in the direction of privacy and may prove beneficial once again in the future.

UPDATE 2021-11-16: Android 12 changes the UI if you ask for ACCESS_FINE_LOCATION. The user now has the option of downgrading you to only getting ACCESS_COARSE_LOCATION access, by choosing "Approximate" instead of "Precise".

Cutpurse answered 8/3, 2016 at 14:13 Comment(11)
How do we know the location provider in Google play service fused api? It may come from NETWORK_PROVIDER or GPS_PROVIDER.Rochelle
@RohitBandil: You don't know what the fused location API will use. You tell the fused location API what you would like. It will decide from there. And, AFAIK, if you only hold ACCESS_COARSE_LOCATION, it will give you "fuzzy" results.Cutpurse
@Cutpurse You mean by this LocationRequest.create().setPriority(/* specify your location providre).We can specify our location providerRochelle
@RohitBandil: No, you specify a priority. That will help the fused location API determine what providers to use. You do not directly specify the provider.Cutpurse
Are these rules still still the same for Android 11?Stole
@IgorGanapolsky: Which rules are you referring to?Cutpurse
@Cutpurse ACCESS_COARSE_LOCATION permissionStole
@IgorGanapolsky: Um, I still am uncertain what rules you are referring to. AFAIK, everything in my answer is still accurate for Android 11.Cutpurse
Super old question. But for Android 12 the answer might deserve an update. I only comment this, because of the relatively new comment stream here.Awad
@Cutpurse For android 12 changes, What will happen if I remove the ACCESS_COARSE_LOCATION from my app permission list and have only ACCESS_FINE_LOCATION? In that case also, will I get the approximate location option.Stupor
@RanjeetKumaryadav: "In that case also, will I get the approximate location option" -- yes. That can be a problem if you cannot use coarse location. You can re-request ACCESS_FINE_LOCATION if the user downgraded you to approximate. See https://mcmap.net/q/218492/-how-can-we-determine-if-we-can-request-location-permission-upgrade-in-android-12/115145 for some notes on this.Cutpurse
E
42

No you don't need to use coarse location.

Coarse location is for network provider's location and fine location is for both GPS provider and network location provider. So fine location covers both and you don't need to use anther one.

In order to receive location updates from NETWORK_PROVIDER or GPS_PROVIDER, you must request the user's permission by declaring either the ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission, respectively, in your Android manifest file. Without these permissions, your application will fail at runtime when requesting location updates.

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 allows access only to NETWORK_PROVIDER.

This is a link for your reference.

Exorcist answered 8/3, 2016 at 14:14 Comment(1)
this is actual answerEngram
R
24

Location can be determined by two ways:

Using NETWORK_PROVIDER
Using GPS_PROVIDER
  1. Using NETWORK_PROVIDER

    Android permissions required for using this provider are either ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION.

  2. Using GPS_PROVIDER

    Android permissions required for using this provider are only ACCESS_FINE_LOCATION

Richma answered 4/9, 2017 at 7:13 Comment(0)
T
3

ACCESS_FINE_LOCATION includes ACCESS_COARSE_LOCATION. However, there is a catch:

ACCESS_COARSE_LOCATION gives you last-known location which is battery friendly https://developer.android.com/training/location/retrieve-current.html#setup This has a dependency on Google Play Services

However, if you need something like live/ real-time location, use ACCESS_FINE_LOCATION It gives you live/ real-time location. You'll need to use a LocationListener though.

Tensimeter answered 26/2, 2020 at 5:26 Comment(0)
V
2

In simple word ACCESS_FINE_LOCATION gives you better and accurate location and ACCESS_COARSE_LOCATION gives you less accurate location.

Vexillum answered 8/1, 2020 at 6:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.