Android R 的一次性许可何时被撤销?

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

一次性权限描述here如下:

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.

所以,为了试用这个新功能,我是这样做的:

我以为这是应该撤销权限的时候,但事实并非如此。当我回到我的应用程序时,我仍然可以打开相机。

那么,一次性许可具体在什么时候被撤销?非常感谢!

根据我的实验,一次性权限似乎对当前进程有好处。一旦您的进程终止(无论出于何种原因),权限授予就会失效。

但是,尚不清楚这是文档错误还是实现错误。跟踪 this issue 以查看未来 Android R 版本会发生什么。

根据对相机权限的试验,一旦授予一次性权限,它将一直保持这种状态,直到应用进程被用户或系统终止。

如果用户杀掉应用,系统会在5秒后撤销权限。这允许应用程序在立即重新启动时不会丢失权限。

如果用户将应用程序后台化,系统会在 1 分钟后撤销权限,从而杀死应用程序的进程。