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

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

问题描述

谷歌正在通过电子邮件告知Android位置权限的变化:
$ b


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



如果您的应用程序需要GPS正常运行,并且您的清单声明中未包含
,那么您的用户可能会遇到糟糕的应用程序
体验。



此外,如果您使用融合位置提供商并希望从GPS获得最准确的位置样本(例如
PRIORITY_HIGH_ACCURACY),则必须包含
b应用程序清单中的android.hardware.location.gps功能为
,确保Google Play仅将您的应用程序分发给带有GPS
传感器的设备。



您可以在 Android开发者帮助$ b中阅读有关此更改的更多信息$ b中心


Android开发者帮助中心


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



如果您同时使用NETWORK_PROVIDER和GPS_PROVIDER,则只需请求ACCESS_FINE_LOCATION权限,因为它包括两个提供者的许可。



警告:如果您的应用程序的目标是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)及更高级别的位置硬件功能。


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


  • 根据第一句话,我想我不需要做任何改变。

  • 基于第二个引号,我想我需要 android.hardware.location.gps android .hardware.location.network 。或者这只适用于 LocationManager 而不是融合地点?



我是否需要 android.hardware.location.gps android.hardware.location.network 或不是?第二个引号告诉你,你需要 android.hardware.location.network code>或 android.hardware.location.gps ,如果您特别需要其中一个或其他位置提供商。



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



如果您需要网络和GPS更新,则应包含< uses-feature> 元素。



如果您不指定,您的设备可能安装在没有提供商的设备上。例如,它可能安装在没有GPS,蜂窝网络或Wi-Fi芯片的设备上。换句话说,获取位置需要网络位置功能或GPS功能。如果您没有声明您的应用程序需要一个或另一个,您可能根本不会获得位置更新。



API 21 vs 20及以下

strong>



请注意,以上仅适用于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表示,网络位置提供商现在已经够好了,因此可以实现更好的位置。


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

From the 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.

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.

  • 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?

Do I need android.hardware.location.gps and android.hardware.location.network or not?

解决方案

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.

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.

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

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.

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 vs 20 and below

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

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 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天全站免登陆