gpt4 book ai didi

android - 我什么时候需要 android.hardware.location.gps 和 android.hardware.location.network?

转载 作者:IT老高 更新时间:2023-10-28 21:49:00 27 4
gpt4 key购买 nike

Google 正在通过电子邮件通知 Android 位置权限的更改:

We’re making a change on October 15th, 2016 that will affect appstargeting API version 21 (Android 5.0, Lollipop) or higher that useACCESS_FINE_LOCATION but don't explicitly have the"android.hardware.location.gps" uses-feature. Going forward, theseapps will be available to install on devices that don't have GPShardware. In most cases this won't be an issue since Wi-Fi and Cell-IDbased location provides high enough fidelity for the typical operationof these apps. However, any apps that require GPS hardware, such asGPS 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 includein your manifest declaration, your users may have a poor appexperience.

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

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

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

我正在使用融合位置提供程序,以 API 21 为目标,并使用 ACCESS_FINE_LOCATION。我并不特别关心 GPS 是否可用,只关心报告最准确的位置。

  • 根据第一个报价,我认为我不必做任何更改。
  • 基于第二个引用,我认为我需要 android.hardware.location.gpsandroid.hardware.location.network。还是这仅适用于 LocationManager 而不是融合位置?

我是否需要 android.hardware.location.gpsandroid.hardware.location.network

最佳答案

第二个引用告诉你你需要android.hardware.location.networkandroid.hardware.location.gps ,如果您特别需要一个或另一个位置提供程序。

如果您想通过 GPS 进行更新,您需要 android.hardware.location.gps .如果您想通过 WiFi 和蜂窝网络进行更新,您需要 android.hardware.location.network .

如果您想同时获得网络和 GPS 的更新,您应该同时包含 <uses-feature>元素。

如果您没有指定,您的设备可能安装在没有该提供程序的设备上。例如,它可能安装在没有 GPS、蜂窝网络或 Wi-Fi 芯片的设备上。

换句话说,获取位置需要网络位置功能或 GPS 功能。如果您不声明您的应用程序需要其中之一,您可能根本无法获得位置更新。

API 21 与 20 及以下

请注意,以上仅适用于 API 21 及更高版本。在 API 21 之前,请求 ACCESS_COARSE_LOCATION许可暗示 location.network功能,而请求 ACCESS_FINE_LOCATION暗示location.gps功能(见 <uses-feature> )。

目前唯一的变化是,对于 API 21+,任何应用请求 ACCESS_FINE_LOCATION很快就可以安装在没有 GPS 的设备上。如果您的应用程序之前假设 GPS 可用(并且需要 GPS),您需要确保您有对 android.hardware.location.gps 的明确请求.

Google 表示,网络位置提供商现在已经可以提供良好的位置,因此发生了变化。

关于android - 我什么时候需要 android.hardware.location.gps 和 android.hardware.location.network?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39603270/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com