Android 6.0 权限.GET_ACCOUNTS [英] Android 6.0 permission.GET_ACCOUNTS

查看:43
本文介绍了Android 6.0 权限.GET_ACCOUNTS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用它来获得许可:

if (ContextCompat.checkSelfPermission(context, Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) {

    // Should we show an explanation?
    if (ActivityCompat.shouldShowRequestPermissionRationale(context, Manifest.permission.GET_ACCOUNTS)) {

    } else {
        // No explanation needed, we can request the permission.
        ActivityCompat.requestPermissions(context, new String[]{Manifest.permission.GET_ACCOUNTS}, PERMISSIONS_REQUEST_GET_ACCOUNTS);

        // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
        // app-defined int constant. The callback method gets the
        // result of the request.
    }
}

但是弹出的权限对话框要求用户访问联系人!?!?

But the pop up dialog for permission asks user for access Contacts!?!?

在 Play 商店 6.0 之前的版本

In pre 6.0 in Play Store with

<uses-permission android:name="android.permission.GET_ACCOUNTS"/>

请求名为 Identity 并说明我需要它来获取设备帐户.

request is named Identity and explains I need it to get device account.

推荐答案

那是因为权限组.基本上,权限被放置在不同的组下,如果授予其中之一,则将授予该组的所有权限.

That is because of Permission Groups. Basically, permissions are placed under different groups and all permissions from that group would be granted if one of them is granted.

例如.在联系人"下,有写/读联系人和获取帐户,因此当您要求其中任何一个时,弹出窗口会要求联系人权限.

Eg. Under "Contacts" , there is write/read contacts and get accounts, so when you ask for any of those, the popup asks for Contacts permissions.

通读:每位 Android 开发者都必须了解的有关新 Android 运行时权限的所有信息

编辑 1

只是想我会添加相关的(不是获取帐户,而是获取权限和组)奥利奥更新信息:
来源:https://developer.android.com/about/versions/oreo/android-8.0-changes.html#rmp

Just thought i'l add the related(not to get accounts but permissions and groups) Oreo update info:
source: https://developer.android.com/about/versions/oreo/android-8.0-changes.html#rmp

在 Android 8.0(API 级别 26)之前,如果应用请求权限在运行时并授予权限,系统也错误地授予应用程序属于相同的其余权限权限组,并在清单中注册.

Prior to Android 8.0 (API level 26), if an app requested a permission at runtime and the permission was granted, the system also incorrectly granted the app the rest of the permissions that belonged to the same permission group, and that were registered in the manifest.

对于面向 Android 8.0 的应用,此行为已得到纠正.这应用程序仅被授予它明确请求的权限.但是,一旦用户授予应用程序权限,所有后续该权限组中的权限请求将自动授予.

For apps targeting Android 8.0, this behavior has been corrected. The app is granted only the permissions it has explicitly requested. However, once the user grants a permission to the app, all subsequent requests for permissions in that permission group are automatically granted.

这篇关于Android 6.0 权限.GET_ACCOUNTS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆