"Allow all the time" location prompt not coming in Android SDK 29

I can't get the "Allow all the time" prompt for location in SDK 29. I already set these permissions in the manifest:

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

and requesting the user to allow these permissions at run time. But it only returns the "When the app is open" and "Deny" choices.

Any thoughts about how to show it in SDK 29.


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            
}

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