In Android-11, If I choose Only This Time permission and access Camera then:
Observed Behaviour: One-Time permission stays granted for a few seconds (approx 3-5 sec) after we kill the application. If I re-open the application instantly or before this short period of time then the permission stays granted and If I re-open it after this short period of time then it will ask permission again and works fine.
Expected Behaviour: The permission will be revoked instantly after we kill the application instead of waiting for any specific period of time.
Is there any solution to it or is it a bug in Android-11? Also, nothing is mentioned in the documentation related to it. https://developer.android.com/guide/topics/permissions/overview#one-time
(P.S: All permission related checks are already implemented in the code.)
Related
I have an app in react native for Android, when a user opens the camera it asks for Permission. In Android 11 user has two options in permission "ONLY THIS TIME" and "WHILE USING THE APP", to give access of the camera.
If the user selects the "ONLY THIS TIME" option, it opens the camera. Then, if the user takes 45 sec to 1 min to click picture, App gets crashes. The same is working fine in case the user selects the "WHILE USING THE APP" option to grant permission.
I think this is happing because, in One Time Permission, Android revokes permission after a few seconds. Let me know if anyone has a better explanation and solution for this. Thanks.
From the android documentation, the ACCESS_BACKGROUND_LOCATION permission should be stated for app that access the background location, user should see the "Allow all the time" option in the permission page of the application.
Yet, there are a lot of sports app, say strava, that track the gps of user continuously, even when app killed or app in background. They didn't even state the permission of ACCESS_BACKGROUND_LOCATION. This can be verify when going to their app permission page, only allow only when using app, ask every time and refuse options are shown. I understand they use foreground service to do such thing, but how come they didn't state for the ACCESS_BACKGROUND_LOCATION permission? Isn't this a must for apps to track user in background as required by Google? Can anyone give me some explaination on this? Thanks
I have researched so much for setting up permissions but everything is either outdated or not helpful. I am looking to set up 3 consecutive requests for files, location, and phone permission for my app. Currently it will ask for files permission only and then start running the app. I have to either reset the app for it to ask for the second permissions or go to app info to manually do it. How do I get it to ask for all 3 permissions upon installing and starting the app up for the first time? Thanks!
One-time permissions are described here as follows:
In Android 11, whenever your app requests a permission related to location, microphone, or camera, the user-facing permissions dialog contains an option called Only this time, as shown in Figure 1. If the user selects this option in the dialog, your app is granted a temporary one-time permission. Your app can access the related data only while one of the following remains true:
Your app's activity has been visible ever since the user granted the
one-time permission.
Your app was visible when the user granted the
permission and has been running a foreground service ever since then.
As long as the foreground service keeps running, your app will retain
the permission even if the user moves your app to the background.
If neither condition is true, you need to ask the user for the
permission again, regardless of target SDK version.
So, to try out this new feature, this is what I did:
I created an app that uses the camera, with no foreground service.
When prompted, I granted the app one-time Camera permission.
After that, I tried pressing Home or open another app to send my app to the background.
I thought this is when the permission is supposed to be revoked, but it's not. When I came back to my app, I can still open the camera.
So, when exactly is a one-time permission revoked? Many thanks!
Based on my experimentation, it appears that the one-time permission is good for the current process. Once your process terminates — for any reason — the permission grant lapses.
However, it is unclear if this is a documentation bug or an implementation bug. Keep track of this issue to see what happens in future Android R releases.
Based on experimenting with the camera permission, once the one-time permission is granted, it remains that way until the app's process is killed either by the user or the system.
If the user kills the app, the system revokes the permission 5 seconds later. This allows the app not to lose the permission if it's immediately restarted.
If the user backgrounds the app, the system revokes the permission 1 minute later, thus killing the app's process.
I am having a hard time understanding the right way to handle a user changing a permission while my app is still running in the background.
In my app I have a location class that registers for location changes and when the location changes the status is sent to a server. However this runs in the background.
When my app is launched I check with the user if its ok to use location services and if so I proceed with setting up that class. However the user can background my app and go into settings and remove that permission. I can, and will certainly check that the permission is enabled in my location class before asking for a location from the location service to avoid a crash. However I am not in an activity when a location comes in so I am not sure how to prompt them that my app needs location services.
EDIT:
It does seem that android restarts your app if a permission has been revoked in settings. However I have confirmed that as of now android does NOT restart your app if a permission was granted though settings.
I read somewhere that your app gets killed when the user changes the permissions on Android-M so you can be sure that this won't change while your app is running. It will been killed when this changes.
As reference check this video: https://www.youtube.com/watch?v=f17qe9vZ8RM
However I am not in an activity when a location comes in so I am not sure how to prompt them that my app needs location services.
Raise a Notification, alerting the user that your app cannot do its intended work without the permission that they revoked. Have the Notification tie into an Activity via a PendingIntent where the user will be able to grant that permission.
Along with CommonsWare suggestion, you can have the onProviderDisabled() to know which provider (gps, network) has been disabled and accordingly requestLocationUpdate() for the one that is still enabled. If both are disabled, see if at least Cell Location is of useful for your app. If so, you can send Cell Location at least till user see notification and re-enable the permission.Use PhoneStateListener to do that.
I would like to try a more modern 2020+ answer to the core question:
However I am not in an activity when a location comes in so I am not sure how to prompt them that my app needs location services.
However I am not in an activity when a location comes in so I am not sure how to prompt them that my app needs location services.
If you are in a normal end user environment:
Respect the users choice to revoke the permission and only display the missing permissions to the user if she opens your activity.
On modern devices your service needs to display a notification in the bar to even be allowed to continue running - change the notification to show the problem.
You are allowed to just ask for most permissions but the user has the ability to deny on the 2nd attempt. After that you get auto-no without anything displayed.
Some permissions (e.g. write settings and overlay) can be accessed by opening the settingspages for this directly - which can be done from a service but will be seen as harassment.
If you are in a work environment:
Best use an official mdm solution (COPE).There you can totally zombiefy your devices allowing nothing or anything and pretty much anything in between. User cannot even enter settings if you dissallow or not even turn the device off or.. you name it.
And apps can get all permissions they need and be installed automatically from the getgo.
For both (eben in mdm sometimes a more powerful user might be wanted):
Please build an extra Activity or Fragment (if you have one that uses those) dedicated to display why your app needs a permission and a button for the user to initiate the request/opening of settings.
It may be much work but users and google will be happy :)