Android:Request Location Permissions
To protect user privacy, apps that use location services must request location permissions.
This page describes the different types of location requirements and provides guidance on how to request location permissions in each case.
Types of location access
Each permission has a combination of the following characteristics:
- Category: Either foreground location or background location.
- Accuracy: Either precise location or approximate location.
Foreground location
If your app contains a feature that shares or receives location information only once, or for a defined amount of time, then that feature requires foreground location access. Some examples include the following:
- Within a navigation app, a feature allows users to get turn-by-turn directions.
- Within a messaging app, a feature allows users to share their current location with another user.
You declare a need for foreground location when your app requests either the ACCESS_COARSE_LOCATION
permission or the ACCESS_FINE_LOCATION
] permission, as shown in the following snippet:
1 |
|
Background location
An app requires background location access if a feature within the app constantly shares location with other users. Several examples include the following:
- Within a family location sharing app, a feature allows users to continuously share location with family members.
The system considers your app to be using background location if it accesses the device’s current location in any situation other than the ones described in the foreground location section.
On Android 10 (API level 29) and higher, you must declare the ACCESS_BACKGROUND_LOCATION
permission in your app’s manifest. On earlier versions of Android, when your app receives foreground location access, it automatically receives background location access as well.
1 |
|
Accuracy
Android supports the following levels of location accuracy:
Approximate
Provides an estimate of the device’s location, to within about 1 mile (1.6 km). Your app uses this level of location accuracy when you declare the
ACCESS_COARSE_LOCATION
permission but not theACCESS_FINE_LOCATION
permission.Precise
Provides an estimate of the device’s location that is as accurate as possible, usually within about 160 feet (50 meters) and sometimes as accurate as within 10 feet (a few meters) or better. Your app uses this level of location accuracy when you declare the
ACCESS_FINE_LOCATION
permission.
- 本文作者:Jacckx
- 本文链接:http://jacckx.me/2021/12/14/Android_Request_Location_Permissions/index.html
- 版权声明:本博客所有文章均采用 BY-NC-SA 许可协议,转载请注明出处!