在我的应用程序中,我需要以下权限才能创建帐户:
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/>
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
据我了解,在 M 中,这些应该自动授予。
但是,我看到的是只有 GET_ACCOUNTS 被授予。我已经用以下代码检查了这一点:
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
logPermissionStatus(Manifest.permission.GET_ACCOUNTS);
logPermissionStatus(Manifest.permission.MANAGE_ACCOUNTS);
logPermissionStatus(Manifest.permission.AUTHENTICATE_ACCOUNTS);
logPermissionStatus(Manifest.permission.USE_CREDENTIALS);
}
private void logPermissionStatus(String permission) {
if (checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED) {
Log.d("AccountPermissions", "Granted: " + permission);
} else {
Log.d("AccountPermissions", "Denied: " + permission);
}
}
哪个打印:
D/AccountPermissions﹕ Granted: android.permission.GET_ACCOUNTS
D/AccountPermissions﹕ Denied: android.permission.MANAGE_ACCOUNTS
D/AccountPermissions﹕ Denied: android.permission.AUTHENTICATE_ACCOUNTS
D/AccountPermissions﹕ Denied: android.permission.USE_CREDENTIALS
如果我尝试请求权限
requestPermissions(new String[] {
Manifest.permission.GET_ACCOUNTS,
Manifest.permission.MANAGE_ACCOUNTS,
Manifest.permission.AUTHENTICATE_ACCOUNTS,
Manifest.permission.USE_CREDENTIALS,
}, 1);
该对话框显示“允许 AccountPermissions 执行未知操作?”,这让我相信这些不是要从用户那里请求的。此外,ACCOUNT 权限组显示在应用信息页面的旧权限下。
我是否需要做一些事情让 Android 自动授予我这些权限,或者我真的应该向用户请求它们?