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

标签 android gps geolocation android-permissions android-gps

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

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.

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

相关文章:

android - 如果我想找到距离给定的纬度经度对最近的沃尔玛,我应​​该在 Android 上使用什么 API?

java - 安卓政策 : External application files

android - 使用自定义操作 View 时未调用 onOptionsItemSelected

android - 当我在我的第一个 fragment 上按下后退按钮时,应用程序应该退出

android - 广播接收器中的定时器功能以识别 Android 应用程序中的 gps?

javascript - navigator.geolocation 给出错误的结果

android - Canvas.drawBitmap() 间歇性变慢,导致白色闪烁

java - 使用 Location.getSpeed 时崩溃

java - Android GPS 应用程序有时会崩溃

python - 提取访问多个(纬度,经度)的 ID 的最大距离