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

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

提交回复
热议问题