我什么时候需要 android.hardware.location.gps 和 android.hardware.location.network? [英] When do I need android.hardware.location.gps and android.hardware.location.network?

查看:30
本文介绍了我什么时候需要 android.hardware.location.gps 和 android.hardware.location.network?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Google is informing by email of changes to the Android location permissions:

我们将于 2016 年 10 月 15 日进行更改,这将影响应用面向 API 版本 21(Android 5.0、Lollipop)或更高版本,使用ACCESS_FINE_LOCATION 但没有明确地拥有android.hardware.location.gps"使用功能.展望未来,这些可以在没有 GPS 的设备上安装应用程序硬件.在大多数情况下,这不是问题,因为 Wi-Fi 和 Cell-ID基于位置的典型操作提供了足够高的保真度这些应用程序.但是,任何需要 GPS 硬件的应用程序,例如GPS 导航器,应明确添加android.hardware.location.gps"uses-feature 到他们的清单中.

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.

如果您的应用需要 GPS 才能正常运行,而您不包括在您的清单声明中,您的用户可能有一个糟糕的应用程序经验.

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.

此外,如果您正在使用融合位置提供程序并希望接收来自 GPS 的最准确的位置样本(即PRIORITY_HIGH_ACCURACY),您必须包括android.hardware.location.gps"应用清单中的功能确保 Google Play 仅将您的应用分发到具有 GPS 的设备传感器.

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.

您可以在 Android 开发者帮助中了解有关此更改的更多信息居中.

来自 Android 开发者帮助中心

为了从 NETWORK_PROVIDER 或 GPS_PROVIDER 接收位置更新,您必须通过在 Android 清单文件中分别声明 ACCESS_COARSE_LOCATION 或 ACCESS_FINE_LOCATION 权限来请求用户的许可.如果没有这些权限,您的应用程序将在运行时请求位置更新时失败.

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.

如果您同时使用 NETWORK_PROVIDER 和 GPS_PROVIDER,那么您只需请求 ACCESS_FINE_LOCATION 权限,因为它包含两个提供商的权限.ACCESS_COARSE_LOCATION 的权限只允许访问 NETWORK_PROVIDER.

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.

注意:如果您的应用面向 Android 5.0(API 级别 21)或更高版本,您必须在清单文件中声明您的应用使用 android.hardware.location.network 或 android.hardware.location.gps 硬件功能,具体取决于关于您的应用是从 NETWORK_PROVIDER 还是从 GPS_PROVIDER 接收位置更新.如果您的应用从这些位置提供程序源中的任何一个接收位置信息,您需要在您的应用清单中声明该应用使用这些硬件功能.在运行 Android 5.0 (API 21) 之前的版本的设备上,请求 ACCESS_FINE_LOCATION 或 ACCESS_COARSE_LOCATION 权限包括对位置硬件功能的隐含请求.但是,请求这些权限不会自动请求 Android 5.0(API 级别 21)及更高版本上的位置硬件功能.

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 是否可用,只关心报告最准确的位置.

I am using the fused location provider, targeting API 21, and using ACCESS_FINE_LOCATION. I don't specifically care whether GPS is available, only that the most accurate location is reported.

  • 根据第一个报价,我认为我不必做任何更改.
  • 基于第二个引用,我认为我需要 android.hardware.location.gpsandroid.hardware.location.network.还是这仅适用于 LocationManager 而不是融合位置?
  • Based on the first quotation, I think I do not have to make any changes.
  • 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?

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

推荐答案

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

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.

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

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.

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

If you want updates from both the network and GPS, you should include both <uses-feature> elements.

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

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.

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

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 与 20 及以下

请注意,以上仅适用于 API 21 及更高版本.在 API 21 之前,请求 ACCESS_COARSE_LOCATION 权限隐含 location.network 功能,而请求 ACCESS_FINE_LOCATION 隐含 location.gps 功能(参见 <uses-特征>).

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

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

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 表示,网络位置提供商现在已经可以提供良好的位置,因此发生了变化.

Google says that network location providers are now good enough for a fine location, thus, the change.

这篇关于我什么时候需要 android.hardware.location.gps 和 android.hardware.location.network?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆