"Allow All The Time" Location Prompt Not Coming In Android SDK 29
Answer :
In order to access the location in background on device running Android 10 (API level 29) or higher, you also need to use below permission in the manifest file
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
please refer the below link for more information
https://developer.android.com/training/location/permissions?hl=fr
Add "ACCESS_BACKGROUND_LOCATION" in manifest and permissions array. If you only add permission in manifest then "Allow all the time" options will not be shown. You need to add in array to ask users to grant at runtime.
In manifest:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
In your activity:
if (ContextCompat.checkSelfPermission( this.applicationContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this@MainActivity, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION), MY_PERMISSIONS_REQUEST_LOCATION) } else { // permission granted }
Add permission ACCESS_BACKGROUND_LOCATION
in the manifest. It is required to show always allow option on android 10 and higher.
See the second point in https://developer.android.com/training/location/background#evaluate
Comments
Post a Comment