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

后端 未结 6 492
爱一瞬间的悲伤
爱一瞬间的悲伤 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 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)

提交回复
热议问题