問題描述
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.gps
和android.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
andandroid.hardware.location.network
. Or is this only forLocationManager
and not fused location?
我是否需要 android.hardware.location.gps
和 android.hardware.location.network
?
推薦答案
第二個引用告訴你需要 android.hardware.location.network
或 android.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?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!