My app uses location data in the foreground only. Because Android 10 distinguishes between location in the background and in the foreground, I want to set the permission in the manifest.xml as minimalistic as possible, as not to bother the user.
The release notes (https://developer.android.com/about/versions/10/privacy/changes) state the following: If I put the target SDK to Android 10 (29) and only request ACCESS_FINE_LOCATION in the manifest (purposely excluding the new ACCESS_BACKGROUND_LOCATION permission), I should only get foreground access (that's what I want).
In the grade file:
compileSdkVersion 29
defaultConfig {
applicationId "com.genewarrior.sunlocator"
minSdkVersion 24
targetSdkVersion 29
versionCode 70
versionName "3.10"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
renderscriptTargetApi 19
renderscriptSupportModeEnabled true
}
In the manifest file:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
However, instead of the expected "Allow only while using the app", it's still possible to choose "Allow all the time" in the Location permission.
Also from time to time the notification "App got your location in the background" pops up, which is exactly what I want to avoid.
Precise location: The app can tell your phone's exact location. In the foreground: The app can use your location only when the app is open on your screen or when you ask the app to do something. In the background: The app can use location info at any time, even if you aren't using it.
Open your phone's Settings app. Under "Personal," tap Location access. At the top of the screen, turn Access to my location on or off.
Permission dialog changes In order to enable background location access, users must set the Allow all the time option for your app's location permission on a settings page, as described in the guide on how to Request background location.
Android offers two location permissions: ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION . The permission you choose determines the accuracy of the location returned by the API. android.
I think what you did is correct. You can request only location permission to "Allow only while using the app" for your app. On the request code you need to request only ACCESS_FINE_LOCATION permission, in this case:
ActivityCompat.requestPermissions(thisActivity, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), 1234)
And put only ACCESS_FINE_LOCATION in the manifest.
You are seeing "Allow all the time" in your app location settings. As suggested by @greywolf82 there is a possibility that ACCESS_BACKGROUND_LOCATION permission is included in some of your dependencies.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With