When do I need android.hardware.location.gps and android.hardware.location.network?

后端 未结 6 493
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-23 20:17

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

相关标签:
6条回答
  • 2020-12-23 20:53

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

    0 讨论(0)
  • 2020-12-23 20:53

    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.

    0 讨论(0)
  • 2020-12-23 20:58

    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.

    0 讨论(0)
  • 2020-12-23 21:03

    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)
    0 讨论(0)
  • 2020-12-23 21:03

    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

    0 讨论(0)
  • 2020-12-23 21:09

    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

    0 讨论(0)
提交回复
热议问题