简体   繁体   English

取消运行时权限请求?

[英]Cancel a Runtime Permission request?

In the android documentation for Runtime permissions for Marshmallow the following code comment refers to cancellation of a permission request: 在Marshmallow的运行时权限的android文档中,以下代码注释指的是取消权限请求:

case MY_PERMISSIONS_REQUEST_READ_CONTACTS: {
        // If request is cancelled, the result arrays are empty.
        if (grantResults.length > 0
            && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

I have not been able to determine how to actually cancel a request for a permission such that the grantResults array returns with a length == 0. The dialog asking for the permission only lets the user allow or deny the request, so cancelling the request by user action isn't obvious. 我无法确定如何实际取消权限请求,以便grantResults数组返回长度== 0.请求权限的对话框只允许用户允许或拒绝请求,因此取消请求用户行为不明显。

However, I ran monkey and it managed to accomplish this at least once. 但是,我跑了猴子,它设法至少完成了一次。

The documentation for onRequestPermissionResult indicates that cancellation is possible. onRequestPermissionResult的文档表明可以取消。

How can I reproduce the case where grantResults will have a length of 0, which indicates it is a cancelled request? 如何重现grantResults的长度为0的情况,这表明它是一个取消的请求? (The String[] grantResults is not null, but has length 0) (String [] grantResults不为null,但长度为0)

Was testing runtime permissions on another application and managed to create a cancel permissions request rather simply. 正在测试另一个应用程序的运行时权限,并设法创建取消权限请求而不是简单。

In the instance of a screen rotation, Android will cancel a permissions request dialog that is currently being displayed and then recreate it. 在屏幕旋转的情况下,Android将取消当前正在显示的权限请求对话框,然后重新创建它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM