-
-
Notifications
You must be signed in to change notification settings - Fork 354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support permission access on Android 11 #422
Comments
Check you have added the required permissions for Also please build and run the example project app as a known working reference to rule out possible causes in your own codebase. |
@dpa99c Thank for response. My AndroidManifest.xml Please help. |
Upon investigation, this is caused by breaking changes in Android 11 to permission states that I've only now just become aware of. In the native Android environment, there are only 3 permission states:
In order to distinguish This works fine up until Android 10. However Android 11, introduces some fundamental breaking changes to the permissions model as outlined here:
Some empirical testing with the Camera permission on Android 11 shows the following results: Before requesting permission:
Requesting permission:
TL;DR: If the user selects the "Only this time" option (either via the permission dialog or directly via settings), once the permission has been revoked for the current app session, this plugin cannot distinguish between this state (where the permission can be requested again via the permissions dialog) and between the "don't ask again" state where the user has pressed "Deny" twice and the permission is permanently denied so cannot be requested again via the permissions dialog. The only way your app can currently handle this outcome is if the reported status is
It may be possible for the plugin to do some heuristic interpretation in this scenario:
So maybe the plugin can set a timer in this sceario to determine if the dialog has been shown and therefore whether to imply which of the above scenarios has taken place. |
Excellent work, thank for your investigation. |
How do you configure the rationale as shown to the user for a location request? The reason I ask is that using "always" location authorisation is currently getting my app rejected - it seems that a customised rationale is required, but I can't see how to configure this. |
@Adam4224 Neither this plugin nor Android itself provide an out-of-the-box UI to display a rationale message to the user - it is up to you how to choose to display this, for example you could use In the case of requesting location "always" (i.e. background location permission), this has recently become much more complex due to changes Google has made to its Play Store policies - see here for details.
|
Hi,
Sorry, it's hard for me to get an exact read on the Android 11 workflow,
since I'm waiting for an Android 11 device to test it on, but I saw this
information from another source:
"*Android 11+: J*ust as in iOS 13/14, Android 11 has changed location
authorization <https://developer.android.com/preview/privacy/location> and
no longer offers the *[Allow all the time]* button on the location
authorization dialog. Instead, Android now offers a hook to present a
custom dialog to the user where you will explain exactly why you
require *"Allow
all the time"* location permission.
This dialog can forward the user directly to your application's *Location
Permissions* screen, where the user must *explicity* authorize *[Allow all
the time]*. "
This is what led me to believe that there was such a mechanism.
…On Mon, 23 Nov 2020, 7:09 pm Dave Alden, ***@***.***> wrote:
@Adam4224 <https://github.com/Adam4224> Neither this plugin nor Android
itself provide an out-of-the-box UI to display a rationale message to the
user - it is up to you how to choose to display this, for example you could
use cordova-plugin-dialogs to display an alert dialog containing the
rational message.
In the case of requesting location "always" (i.e. background location
permission), this has recently become much more complex due to changes
Google has made to its Play Store policies - see here
<https://support.google.com/googleplay/android-developer/answer/9799150>
for details.
Specifically:
Your app must display a prominent disclosure through a pop-up alert before
your app’s location runtime permission. Based on our review, a prominent
disclosure did not appear before the runtime permission.
Please add a prominent disclosure and make sure it appears before the
location runtime permission.
Remember, your prominent disclosure must:
Appear before your app’s location runtime permission.
Include at least the following sentence, adapted to include all the
relevant features requesting access to location in the background in the
app that are readily visible to the user: “This app collects location data
to enable ["feature"], ["feature"], & ["feature"] even when the app is
closed or not in use.”
Include any other details necessary to make it clear to the user how and
why you are using location in the background. While additional content is
permitted, it should not cause the required content to not be immediately
visible.
Include the following sentence, if you extend permitted usage to ads:
“This data is also used to provide ads.”
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#422 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKQGQEY5FY7JG2KY6HEB44DSRKXQLANCNFSM4TPIQSFA>
.
|
@dpa99c , the location permission statuses defined in the android module don't contain 'authorized_when_in_use' status, which is what is returned on an Android 11 device running an app with 'While Using The App' permission. Is there a fix you are planning to deal with thes new changes? |
FYI, I had the exact same issue on Android 11 with
On Android 10 (and before) :
On Android 11 :
|
Hello, Same as @fcamblor :
|
hi all! |
@kunalpunjrath Unlike iOS, which has a explicit constants to differentiate when-in-use vs always, Android does not provide such a differentiation. In the case of location permission on Android 10 / API 29 and above, it's possible to infer this: if However, for other permissions on Android where "When in use" is an option (e.g. Camera, Microphone), there's no way to differentiate between the user pressing "When in use" or "Allow once": in both cases, the outcome Android delivers to |
@fcamblor On Android 11+, you can no longer call You must first call This is intentional behaviour of Android 11+, not an artefact of this plugin therefore it's not possible to change this behaviour. |
With regard to my earlier comment regarding a possible workaround for the behaviour when the user presses "Only this time": It's not possible (as I suggested it might be in that comment) to workaround this issue by measuring the time taken between requesting a permission and receiving a permission request response.
In both cases, Android responds with Therefore the only way to handle this situation is: to check the current authorization status for the permission; if it returns If the outcome is that permission was denied, whether due to user actively denying permission, or implicitly due to previously denying permission twice (always), you would handle this in the same way (i.e. inform user that permission is needed and how to change in Settings). Therefore I don't believe this plugin can be changed in order to work around behaviour which is intentional in the permissions model of Android 11+ |
As a reference for others, here's how I'm handling the "Only this time" permission on Android 11+ which results in permission status being returned as You can see an working example of this in this example project: https://github.com/dpa99c/cordova-diagnostic-plugin-android-runtime-example/ Here's a short example using
|
Thanks @dpa99c ! I really appreciate you taking the time to document this. Stuff like this is never as simple as it seems, and having a good code snippet to follow makes a huge difference. (thanks as an side for all the good plugins you maintain in the cordova ecosystem too) |
The text was updated successfully, but these errors were encountered: