Sample project for background location acquisition on Android 10 and above
It is better to get location information with the foreground service
If the app wants to get location information in the background from Android 10, it needs permission of ACCESS_BACKGROUND_LOCATION.
However, when handling location information in the foreground service, it is possible to acquire location information without requiring permission for ACCESS_BACKGROUND_LOCATION.
In that case, you need to specify location
in [foregroundServiceType] (https://developer.android.com/reference/android/R.attr#foregroundServiceType) of the foreground service.
link1 link2 link3 link4 link5 link6 link7 link8
device | foreground | background |
---|---|---|
Pixel 4 OS:13 | ||
Pixel 4 OS:12 | OK | OK |
Pixel 4 OS:10 | OK | OK |
Screen | Notification |
---|---|
Screen | Notification |
---|---|
Screen | Notification |
---|---|
background
From Android 10, the item "Allow only while using the app" has been added to the selection items on the app settings screen.
If "Allow only while using the app" is checked, location information in the background will not be performed.