Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is an Android R's one-time permission revoked?

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!

like image 586
huytc Avatar asked Nov 16 '25 04:11

huytc


1 Answers

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.

like image 80
CommonsWare Avatar answered Nov 17 '25 18:11

CommonsWare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!