41

Google is informing by email of changes to the Android location permissions:

We’re making a change on October 15th, 2016 that will affect apps targeting API version 21 (Android 5.0, Lollipop) or higher that use ACCESS_FINE_LOCATION but don't explicitly have the "android.hardware.location.gps" uses-feature. Going forward, these apps will be available to install on devices that don't have GPS hardware. In most cases this won't be an issue since Wi-Fi and Cell-ID based location provides high enough fidelity for the typical operation of these apps. However, any apps that require GPS hardware, such as GPS navigators, should explicitly add the "android.hardware.location.gps" uses-feature to their manifest.

If your app requires GPS to function properly and you do not include in your manifest declaration, your users may have a poor app experience.

Also, if you’re using the fused location provider and wish to receive the most accurate location samples from GPS (i.e. with PRIORITY_HIGH_ACCURACY), you must include the "android.hardware.location.gps" feature in your app’s manifest to ensure that Google Play only distributes your app to devices with GPS sensors.

You can read more about this change in the Android Developers Help Center.

From the Android Developers Help Center

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.

Caution: If your app targets Android 5.0 (API level 21) or higher, you must declare that your app uses the android.hardware.location.network or android.hardware.location.gps hardware feature in the manifest file, depending on whether your app receives location updates from NETWORK_PROVIDER or from GPS_PROVIDER. If your app receives location information from either of these location provider sources, you need to declare that the app uses these hardware features in your app manifest. On devices running verions prior to Android 5.0 (API 21), requesting the ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permission includes an implied request for location hardware features. However, requesting those permissions does not automatically request location hardware features on Android 5.0 (API level 21) and higher.

I am using the fused location provider, targeting API 21, and using ACCESS_FINE_LOCATION. I don't specifically care whether GPS is available, only that the most accurate location is reported.

  • Based on the first quotation, I think I do not have to make any changes.
  • Based on the second quotation, I think I need both android.hardware.location.gps and android.hardware.location.network. Or is this only for LocationManager and not fused location?

Do I need android.hardware.location.gps and android.hardware.location.network or not?

Community
  • 1
  • 1
mattm
  • 5,851
  • 11
  • 47
  • 77
  • 2
    Read the Caution note very carefully: If your app targets Android 5.0 or higher you MUST declare that your app uses the hardware feature in the manifest file. In API levels before 21 the request for location hardware features was implied, but it is no longer the case. Remember, if your app can function without location services, you can make the declaration with the android:required attribute set to "False". – Yves Rochon Sep 22 '16 at 14:45
  • @YvesRochon If my app uses gps on some pages not at all so what should i do keep it required attribute false or true – Pawan asati Oct 05 '16 at 10:41
  • 1
    @Pawan asati It depends, if the functionality of your app requires location services to work on any page, then you can set required to true, if on all pages the functionality can be used but is not 100% mandatory, you can set it to false. – Yves Rochon Oct 05 '16 at 12:31

6 Answers6

18

The second quotation is telling you that you need either android.hardware.location.network or android.hardware.location.gps, if you specifically need one or the other location provider.

If you want updates via GPS, you need android.hardware.location.gps. If you want updates via the WiFi and cellular networks, you need android.hardware.location.network.

If you want updates from both the network and GPS, you should include both <uses-feature> elements.

If you don't specify either, your device may be installed on devices without that provider. For example, it may be installed on a device without a GPS, cellular network, or Wi-Fi chip.

In other words, getting location requires either the network location feature or the GPS feature. If you don't declare that your application needs one or the other, you may not get location updates at all.

API 21 vs 20 and below

Note that the above is only true for API 21 and above. Prior to API 21, requesting the ACCESS_COARSE_LOCATION permission implied the location.network feature, wheras requesting ACCESS_FINE_LOCATION implied the location.gps feature (see <uses-feature>).

The only change right now is that, for API 21+, any app requesting ACCESS_FINE_LOCATION will soon be available to install on devices without GPS. If your app previously assumed GPS was available (and needs GPS), you need to make sure you have the explicit request for android.hardware.location.gps.

Google says that network location providers are now good enough for a fine location, thus, the change.

da Rocha Pires
  • 2,443
  • 1
  • 24
  • 19
Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120
  • 11
    Dear downvoter: I would appreciate your feedback so that I can improve this answer if it is incomplete or incorrect. – Bryan Herbst Sep 20 '16 at 20:45
  • 4
    I'm very sorry to take so long to post the feedback, I was finishing writting my answer. I downvoted it because as far as my understanding goes, your answer is not correct. `uses-feature` is only a filter on devices that your app can potentially be installed, and as per OP question, he only needs some location, and not necessarly the one coming from the GPS. On my answer I defend and further explain this point and I welcome you to comment, counter argument, etc – Budius Sep 20 '16 at 20:50
  • @Budius we seem to be saying the same thing, but in different ways. I've edited my answer to clarify my points. – Bryan Herbst Sep 20 '16 at 21:26
  • 1
    Retracted and changed to up – Budius Sep 20 '16 at 21:37
  • @Tanis.7x I am out of the question topic here. But Can you tell me, whether we should ask permission at the we launch application? Thank – K.Sopheak Sep 22 '16 at 04:33
  • 1
    @K.Sopheak that is completely up to you. Google recommends asking in context (e.g. when the user opens a map or something) to provide a clear value for granting the permission, but if your app clearly requires location anyway (e.g. a navigation app), asking up front might be fine. – Bryan Herbst Sep 22 '16 at 13:39
  • @Tanis.7x Thank for comment and suggestion. – K.Sopheak Sep 23 '16 at 04:06
  • 1
    @Tanis.7x I corrected from "ACCESS_COURSE_LOCATION" to "ACCESS_COARSE_LOCATION". I also needed to add a couple of commas so the minimum of 6 character changes was performed. Sorry for that and thank you for the answer. – da Rocha Pires Sep 27 '16 at 13:26
  • @Tanis.7x & Budius - I have same question, So what i suppose to use - android.hardware.location.gps or android.hardware.location.network Or both the features in my application. (Need help to what to use) I am using this permission. Note - I havent used fused location in my application. – umesh Sep 28 '16 at 10:00
  • @umesh If you don't use location, you don't need either. If you use location, then include `.gps` if you want to ensure you get updates via GPS, `.network` if you are okay with only getting location updates from WiFi/cell networks, or both if you want both. – Bryan Herbst Sep 28 '16 at 14:27
  • @Tanis.7x thank you for your answer. I'm using API 19 (4.4.2) for my app and in my Manifest file I'm targeting API 21 and I have the following rows: ` `. Do i need to update the Manifest? – smartmouse Dec 29 '16 at 16:03
  • 1
    @smartmouse you should not notice any change with what you currently have. The only difference is that your app may be installed on devices without GPS. If that is a problem, you need to explicitly declare that you use the GPS feature. – Bryan Herbst Dec 29 '16 at 17:53
  • I disagree with "getting location requires either the network location feature or the GPS feature. If you don't declare that your application needs one or the other, you may not get location updates at all." I think that using either the `ACCESS_COARSE_LOCATION` or `ACCESS_FINE_LOCATION` permissions alone will result in an implicit `android.hardware.location` uses-feature, and this will prevent installation on a device with neither. I tried to describe this in my answer. – mattm Jan 04 '17 at 21:15
15

TL;DR: No, you don't have to add uses-feature to your manifest, but depending, you might.

complete answer:

uses-feature of the manifest is only so that Google Play can filter out devices that does not contain a feature that is necessary for the application to execute correctly. (Examples are GPS for a turn-by-turn navigation app, or Camera for a camera app).

Read carefully this quote:

any apps that require GPS hardware, such as GPS navigators, should explicitly add the "android.hardware.location.gps" uses-feature to their manifest

(...)

and wish to receive the most accurate location samples from GPS

As you mention, you only care that the FusedLocationProvider gives you the best location available to the device is installed. That means, even though you're requesting PRIORITY_HIGH_ACCURACY, your app might get installed on devices that does not contain GPS and will never get a location as accurate as a GPS, or maybe even (in some very rare odd case), be installed on device that does not contain any location provider.

edit:

Based on the second quotation, I think I need both android.hardware.location.gps and android.hardware.location.network. Or is this only for LocationManager and not fused location?

I just went digging on the docs https://developer.android.com/guide/topics/manifest/uses-feature-element.html#hw-features and found it very interesting, there're 3 possibilities:

  • android.hardware.location
  • android.hardware.location.gps
  • android.hardware.location.network

so based on that, if your application cannot work without any form of location you should use the first one android.hardware.location, else, if your app uses location but it's not essential to its funcionality, you can be free to not include anything

Community
  • 1
  • 1
Budius
  • 39,391
  • 16
  • 102
  • 144
  • furthermore all, the app I work uses location, but it's not core funcionality and the app can totally work without any location, and we don't declare any of it, never did and it works fine – Budius Sep 20 '16 at 20:55
  • 4
    If your app doesn't need location, you should still include the `` element, but with `required` set to false. By requesting the location permission you imply you require the location feature and your app may not be available to devices without any location features. – Bryan Herbst Sep 20 '16 at 21:31
  • What should I use then gps or network in my applicatoin? Will it affect on my application if I didnt use anything? – umesh Sep 28 '16 at 10:15
10

Quick and simple solution:

App needs to updates via GPS use android.hardware.location.gps. If you want updates via the WiFi and cellular networks, you need android.hardware.location.network.

Add below lines to your manifests file based on your location data requirements:

<uses-feature android:name="android.hardware.location.network" android:required="false" />
<uses-feature android:name="android.hardware.location.gps" android:required="false" />

Hope this helps..

Jatin
  • 1,650
  • 3
  • 17
  • 32
  • 2
    I believe you want the first one to be android.hardware.location.network – zgc7009 Sep 22 '16 at 13:16
  • 1
    This answer does not provide guidance on when uses-feature elements should be present or why they are set with required=false. In my particular case, I definitely do not want devices without any location capability to install my application. – mattm Sep 26 '16 at 16:38
  • This is the answer for me, though I agree with mattm that it needs a bit of qualification. I was looking for the correct `uses-feature` clauses to allow GPS and/or network based location features but not to require them for installation. My app can work without location features so should be installable on devices without GPS or network location ability, BUT if any type of location IS available on the device then I want the app to have access to it for the best user experience. (looks like `android.hardware.location.network` is needed in the first clause, though, as zgc7009 says) – Fat Monk Oct 24 '16 at 12:51
2

From my understanding, it is sufficient to read the documentation for the uses-feature element to understand how applications are filtered in Google Play based upon implicit and explicit uses-feature entries:

Google Play filters the applications that are visible to users, so that users can see and download only those applications that are compatible with their devices. One of the ways it filters applications is by feature compatibility.

To determine an application's feature compatibility with a given user's device, Google Play compares:

Features required by the application — an application declares features in elements in its manifest with... Features available on the device, in hardware or software — a device reports the features it supports as read-only system properties.

...

If a feature is explicitly declared as being required, Google Play adds the feature to the list of required features for the application. It then filters the application from users on devices that do not provide that feature.

If a feature is explicitly declared as not being required, Google Play does not add the feature to the list of required features. For that reason, an explicitly declared non-required feature is never considered when filtering the application. Even if the device does not provide the declared feature, Google Play will still consider the application compatible with the device and will show it to the user, unless other filtering rules apply.


The implicit uses-feature items for location permissions are:

ACCESS_COARSE_LOCATION

  • android.hardware.location
  • android.hardware.location.network (Only when target API level is 20 or lower.)

ACCESS_FINE_LOCATION

  • android.hardware.location
  • android.hardware.location.gps (Only when target API level is 20 or lower.)

The change described in Google's email message is that the implicit uses-feature items for android.hardware.location.gps will not be present in API 21+ with ACCESS_FINE_LOCATION. The analogous situation appears to be true for ACCESS_COARSE_LOCATION and android.hardware.location.network.

Google encourages explicit enumeration of all uses-feature entries, but still provides implicit entries based on permissions. From the following documentation excerpt, I think there is no difference between omitting a uses-feature and declaring it not required, unless there is an implicit uses-feature entry.

If a feature is explicitly declared as not being required, Google Play does not add the feature to the list of required features.


Your application's use case determines what uses-feature entries should be present. Here are some example use cases, with all uses-feature entries being required unless otherwise stated:

  1. Application uses GPS explicitly from LocationManager or application needs GPS' high accuracy. This is the example given in Google's email.

    • ACCESS_FINE_LOCATION
    • android.hardware.location (implicit)
    • android.hardware.location.gps (implicit up to API 20)
  2. Uses Network location explicitly

    • ACCESS_COARSE_LOCATION
    • android.hardware.location (implicit)
    • android.hardware.location.network (implicit up to API 20)
  3. Uses both GPS and Network

    • ACCESS_FINE_LOCATION
    • android.hardware.location (implicit)
    • android.hardware.location.gps (implicit up to API 20)
    • android.hardware.location.network
  4. Uses at least one of GPS and Network. This is my FusedLocationProviderApi case in the original question.

    • ACCESS_FINE_LOCATION/ACCESS_COARSE_LOCATION
    • android.hardware.location (implicit)
  5. Uses location if available, still allows application installation if not available

    • ACCESS_FINE_LOCATION
    • android.hardware.location required=false (override implicit)
    • android.hardware.location.gps required=false (override implicit up to API 20)
Asif Patel
  • 1,744
  • 1
  • 20
  • 27
mattm
  • 5,851
  • 11
  • 47
  • 77
  • Hi @mattm, Still not clear to me. Do I need to explicitly include android.hardware.location.GPS uses-feature, if I'm using Google Play Services Fused Location Provider? – Vinay Kashyap T S Sep 07 '18 at 07:37
  • @VinayKashyapTS The 5 cases I outlined above apply to the Fused Location Provider. It depends on whether you want GPS specifically, or are satisfied with location from network sources, or want location if available but will still operate without it. – mattm Sep 07 '18 at 12:53
1

On your first point:

Based on the first quotation, I think I do not have to make any changes.

You don't need to make any changes because you are using FusedLocation which automatically detects GPS and NetworkProvider as per availability and gives you the best estimate location (You need to add ACCESS_FINE_LOCATION permission to get High Accuracy). So even if you're targeting API above 21 you don't need to change anything in your app -FusedLocation will work as before.

And on your second point:

Based on the second quotation, I think I need both android.hardware.location.gps and android.hardware.location.network. Or is this only for LocationManager and not fused location?

You just need to ignore it because you're using FusedLocation API and you are not using LocationManager API which you replaced by FusedLocation. So second Quotation is only for apps which use LocationManagar.

NETWORK_PROVIDER and GPS_PROVIDER are part of LocationManager Not FusedLocation API

Melquiades
  • 8,496
  • 1
  • 31
  • 46
androidXP
  • 1,692
  • 3
  • 27
  • 58
  • The third paragraph in the first document reference states fused location still requires the `android.hardware.loction.gps` feature... – zgc7009 Sep 22 '16 at 13:18
  • Read again its from **Location Strategies** if you click links it will pointing towards `LocationManager API` so for fused location you don't need it.I already developed few apps with fused location and i never put GPS or Network Permission in Manifest – androidXP Sep 22 '16 at 15:02
  • @zgc7009 Yes and its for only LocationManager API, That's how its works – androidXP Sep 22 '16 at 17:27
  • I'm confused. Why would they explicitly state you need to add it for fused location provider? The idea of the feature request is to make sure people have GPS, which is very much so needed for the fused location provider to work like it is supposed to. You can set the required flag to false, but according to this message from Google you will need to start adding it for any app utilizing fused location provider. If I am wrong, could you provide direct documentation to state otherwise? – zgc7009 Sep 22 '16 at 19:21
  • Please check Google I/O of Fused Location it has better explanation then documentation – androidXP Sep 22 '16 at 21:02
  • But the whole point is that this is changing, it isn't like it used to be. In the past, you are correct, but they are explicitly stating there is a change to the way things are handled starting October 15. That is why I am confused. The FusedLocation I/O was from 3 years ago... – zgc7009 Sep 22 '16 at 21:14
  • Just wait and see we wouldn't need any additional permission – androidXP Sep 22 '16 at 23:07
1

Yes you need both the permissions if you are using fused provider.

ACCESS_COARSE_LOCATION - To receive location updates from NETWORK_PROVIDER. Adding android.hardware.location.network feature permission is enough.

ACCESS_FINE_LOCATION - To receive location updates from both NETWORK_PROVIDER and GPS_PROVIDER. You should add both android.hardware.location.gps and android.hardware.location.network feature permissions. Applicable for also fused location.

Asif Patel
  • 1,744
  • 1
  • 20
  • 27
Eshack Nazir
  • 354
  • 3
  • 16