I am calling the code below in an Android app (for authenticating against Google App Engine, think that is by-the-by):
AccountManager accountManager = AccountManager.get(this);
accountManager.getAuthToken(mAccount, "ah",null, false, new GetAuthTokenCallback(), null);
In GetAuthTokenCallback()
this error is thrown:
android.accounts.AuthenticatorException: java.lang.UnsupportedOperationException: getAuthTokenLabel not supported
The authentication process stops there.
The odd thing is that it runs on a Android 5.5.1 device perfectly; the UnsupportedOperationException only error occurs on a 6.0.1 device.
I have runtime permission request for GET_ACCOUNTS
which I think I need but suspect the error stems from this and Marshmellow's permissions systems.
@TargetApi(23)
private boolean haveGetAccountPermission() {
Log.i(TAG, "haveGetAccountPermission()");
int hasWriteContactsPermission = ActivityCompat.checkSelfPermission(this,Manifest.permission.GET_ACCOUNTS);
if (hasWriteContactsPermission != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,new String[] {Manifest.permission.GET_ACCOUNTS},
REQUEST_CODE_ASK_PERMISSIONS);
return false;
} else {
return true;
}
}
Any ideas much appreciated.
I don't know if this helps, but I've found that creating a new account immediately before executing
getAuthToken()
throws this exception.In my case, I was trying to rename an account, and I found that if I first execute
getAuthToken()
with the old account and then create a new account with its contents, the exception would no longer be thrown.I'm suspicious that this may be a bug in Marshmallow.