Android 6.0 permission.GET_ACCOUNTS
Android 6.0 permission.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.
}
}
但是弹出的权限对话框要求用户访问通讯录!?!?
Play 商店中的 6.0 之前版本
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
请求名为身份并说明我需要它来获取设备帐户。
GET_ACCOUNTS
was moved into the CONTACTS
permission group in Android 6.0。虽然 API 让我们提供权限,但系统会提示用户(至少对于 Android 6.0)提供权限组。因此,用户将得到与 READ_CONTACTS
或 WRITE_CONTACTS
.
相同的提示 GET_ACCOUNTS
我先把你的问题弄错了。在此页面http://developer.android.com/guide/topics/security/permissions.html#perm-groups,您可以看到GET_ACCOUNTS指的是权限组联系人。因此,系统会提示您获得联系权限。
在 Marshmallow 中,所有危险权限都属于权限组。
权限android.permission.GET_ACCOUNTS
属于CONTACTS组
您可以在此处找到有关危险权限及其组的更多信息:
https://developer.android.com/guide/topics/security/permissions.html#normal-dangerous
那是因为权限组。基本上,权限放在不同的组下,如果授予其中一个权限,则该组的所有权限都将被授予。
例如。在 "Contacts" 下,有 write/read 个联系人和获取帐户,因此当您请求其中任何一个时,弹出窗口会询问联系人权限。
通读:Everything every Android Developer must know about new Android's Runtime Permission
编辑 1
只是想我会添加相关的(不是为了获取帐户而是权限和组)Oreo 更新信息:
来源:https://developer.android.com/about/versions/oreo/android-8.0-changes.html#rmp
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.
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 N
中改变
http://developer.android.com/preview/behavior-changes.html#perm
The GET_ACCOUNTS permission is now deprecated. The system ignores this
permission for apps that target Android N.
如果您使用 GET_ACCOUNTS 权限要求用户 select 设备上的特定帐户类型(Google 在我的例子中),您可以使用 AccountPicker class 不需要任何特殊权限
Intent intent = AccountPicker.newChooseAccountIntent(null, null,
new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE},
false, null, null, null, null);
try {
startActivityForResult(intent, REQUEST_ACCOUNT_PICKER);
} catch (ActivityNotFoundException e) {
// This device may not have Google Play Services installed.
}
您需要 Google 在您的 gradle 依赖项中进行 Play 服务授权
implementation com.google.android.gms:play-services-auth:16.0.1
这避免了我的联系人权限弹出窗口
我正在使用它来获得许可:
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.
}
}
但是弹出的权限对话框要求用户访问通讯录!?!?
Play 商店中的 6.0 之前版本
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
请求名为身份并说明我需要它来获取设备帐户。
GET_ACCOUNTS
was moved into the CONTACTS
permission group in Android 6.0。虽然 API 让我们提供权限,但系统会提示用户(至少对于 Android 6.0)提供权限组。因此,用户将得到与 READ_CONTACTS
或 WRITE_CONTACTS
.
GET_ACCOUNTS
我先把你的问题弄错了。在此页面http://developer.android.com/guide/topics/security/permissions.html#perm-groups,您可以看到GET_ACCOUNTS指的是权限组联系人。因此,系统会提示您获得联系权限。
在 Marshmallow 中,所有危险权限都属于权限组。
权限android.permission.GET_ACCOUNTS
属于CONTACTS组
您可以在此处找到有关危险权限及其组的更多信息:
https://developer.android.com/guide/topics/security/permissions.html#normal-dangerous
那是因为权限组。基本上,权限放在不同的组下,如果授予其中一个权限,则该组的所有权限都将被授予。
例如。在 "Contacts" 下,有 write/read 个联系人和获取帐户,因此当您请求其中任何一个时,弹出窗口会询问联系人权限。
通读:Everything every Android Developer must know about new Android's Runtime Permission
编辑 1
只是想我会添加相关的(不是为了获取帐户而是权限和组)Oreo 更新信息:
来源:https://developer.android.com/about/versions/oreo/android-8.0-changes.html#rmp
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.
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 N
中改变http://developer.android.com/preview/behavior-changes.html#perm
The GET_ACCOUNTS permission is now deprecated. The system ignores this permission for apps that target Android N.
如果您使用 GET_ACCOUNTS 权限要求用户 select 设备上的特定帐户类型(Google 在我的例子中),您可以使用 AccountPicker class 不需要任何特殊权限
Intent intent = AccountPicker.newChooseAccountIntent(null, null,
new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE},
false, null, null, null, null);
try {
startActivityForResult(intent, REQUEST_ACCOUNT_PICKER);
} catch (ActivityNotFoundException e) {
// This device may not have Google Play Services installed.
}
您需要 Google 在您的 gradle 依赖项中进行 Play 服务授权
implementation com.google.android.gms:play-services-auth:16.0.1
这避免了我的联系人权限弹出窗口