How do you force AccountManager to show the “Access Request” screen after a user has already allowed access?

*爱你&永不变心* 提交于 2019-11-27 13:39:58

The only solution I've found is to manually clear out the data stored in the system's accounts.db. Run the following from the command line to clear out all account grants on the system.

For the emulator:

adb -e shell 'sqlite3 /data/system/accounts.db "delete from grants;"'

For a device (must be rooted and have the sqlite3 binary installed):

adb -d shell 'echo sqlite3 /data/system/accounts.db \"delete from grants\;\" | su'

I have created a new account which I use for testing. A new account will always prompt for Access Request. Remember to NOT allow access.

To test for the login screen, change the password for the account from another device/PC.

Using Google Play Services:

http://developer.android.com/reference/com/google/android/gms/auth/GoogleAuthUtil.html

Add https://www.googleapis.com/auth/userinfo.profile to your scope.

Example:

String scope="oauth2:https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile"

final String token = GoogleAuthUtil.getToken(context, "xxxx@gmail.com", scope);

OR "brute force"

Intent res = new Intent();
res.addCategory("account:xxxx@gmail.com");
res.addCategory("scope:oauth2:https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile");
res.putExtra("service", "oauth2:https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile");
Bundle extra= new Bundle();
extra.putString("androidPackageName","com.your.package");
res.putExtra("callerExtras",extra);
res.putExtra("androidPackageName","com.your.package");
res.putExtra("authAccount","xxxx@gmail.com");

String mPackage = "com.google.android.gms";
String mClass = "com.google.android.gms.auth.TokenActivity";
res.setComponent(new ComponentName(mPackage,mClass));
startActivityForResult(res,100);

Now, when you revoke the access here https://accounts.google.com/IssuedAuthSubTokens the application shows you the window for permission again in the device.

In my case what Benn Sandoval says does not work.

I had to revoke permissions programmatically and then connect again.

if (googleApiClient != null && !googleApiClient.isConnecting() && googleApiClient.isConnected()){

    googleApiClient.clearDefaultAccountAndReconnect();
    Plus.AccountApi.revokeAccessAndDisconnect(googleApiClient).setResultCallback(new ResultCallback<Status>() {
        @Override
        public void onResult(Status status) {
            Log.i("google+", "Google+ user access revoked");
            googleApiClient.connect();
        }
    });
}

Doing this i was getting asked again to grant permissions to google+

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!