In Android 10, when asking for some permission like Location, the system prompts the user 3 options:
Allow APP to access this device's location?
-Allow all the time
-Allow only while using the app
-Deny
Is there a way to know how exactly has been granted? I use this code to know if location is granted:
boolean hasPermission = (ContextCompat.checkSelfPermission(oContext, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED);
But I need to know if it has been granted "all the time" or just "while using the app". What I really need is to have permission all the time as my app has a background location service. So I need to know if the permission has been granted to to that, or the possibility to ask for the permission but without the option of allowing it "only when using the app".
requestPermissions(Context, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 123);
Open Settings > Location > App Permission > Maps. Then choose between the available options to use location all the time or only while using the app. For the full features of Google Maps to work it's best to allow location access all the time.
To check if the user has already granted your app a particular permission, pass that permission into the ContextCompat. checkSelfPermission() method. This method returns either PERMISSION_GRANTED or PERMISSION_DENIED , depending on whether your app has the permission.
This example demonstrates how do I request Location permission in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.
You can use:
boolean backgroundLocationPermissionApproved =
ActivityCompat.checkSelfPermission(this,
permission.ACCESS_BACKGROUND_LOCATION)
There is no possibility to prompt the user without letting him choose the "only when using the app" option.
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