且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Android M 中检查单个请求的多个权限?

更新时间:2021-12-18 22:45:54

您可以在单个请求中请求多个权限(来自不同组).为此,您需要将所有权限添加到作为第一个参数提供给 requestPermissions API 的字符串数组中,如下所示:

You can ask multiple permissions (from different groups) in a single request. For that, you need to add all the permissions to the string array that you supply as the first parameter to the requestPermissions API like this:

requestPermissions(new String[]{
                                Manifest.permission.READ_CONTACTS,
                                Manifest.permission.ACCESS_FINE_LOCATION},
                        ASK_MULTIPLE_PERMISSION_REQUEST_CODE);

执行此操作时,您将看到权限弹出窗口是多个权限弹出窗口的堆栈.当然,您需要处理每个权限的接受和拒绝(包括不再询问")选项.此处一>.

On doing this, you will see the permission popup as a stack of multiple permission popups. Ofcourse you need to handle the acceptance and rejection (including the "Never Ask Again") options of each permissions. The same has been beautifully explained over here.