问题
In my app, I need the following permissions for creating an account:
<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"/>
It is my understanding that in the M, these should be granted automatically.
However, what I'm seeing is that only GET_ACCOUNTS is granted. I've checked this with the following code:
@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);
}
}
Which prints:
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
If I try to request the permissions
requestPermissions(new String[] {
Manifest.permission.GET_ACCOUNTS,
Manifest.permission.MANAGE_ACCOUNTS,
Manifest.permission.AUTHENTICATE_ACCOUNTS,
Manifest.permission.USE_CREDENTIALS,
}, 1);
The dialog says "Allow AccountPermissions to perform an unknown action?", leading me to believe that these are not intended to be requested from the user. Additionally, the ACCOUNT permission group shows up under legacy permissions on the app info page.
Do I need to do something to get Android to grant me these permissions automatically, or am I really supposed to request them from the user?
回答1:
This was fixed in the latest M preview.
回答2:
AUTHENTICATE_ACCOUNTS, MANAGE_ACCOUNTS, USE_CREDENTIALS no longer exist. We scoped the APIs such that only the authenticator's UID can perform the operations that were protected by these permissions. Normal apps do not have a valid use case for using these operations.
https://code.google.com/p/android-developer-preview/issues/detail?id=2592
来源:https://stackoverflow.com/questions/30963261/not-all-permissions-in-account-permission-group-granted-automatically