मैं (केवल परीक्षण के लिए) परछाई उपयोग करने की कोशिश। दुर्भाग्य से, यह एक SecurityException फेंकता है क्योंकि Android जाँच करता है कि फोन करने वाले एक सिस्टम एप्लिकेशन है ...
संदर्भ के लिए, कोड है:
/**
* Revoke the fact that current app is allowed to retrieve an authToken for an account.
* @param accountName The account whose permissions are being revoked
* @param context current context
* @return true if revoked successfully, false otherwise
*/
public static boolean revokeAppPermission(String accountName, Context context) {
if (accountName == null) {
Log.w(TAG, "revokeAppPermission: abort, account missing.");
return false;
}
AccountManager accountManager = AccountManager.get(context);
Account[] accounts = accountManager.getAccounts();
Account accountToRevoke = null;
for (Account account : accounts) {
if (accountName.equals(account.name)) {
accountToRevoke = account;
break;
}
}
if (accountToRevoke == null) {
Log.w(TAG, "revokeAppPermission: abort, no account found.");
return false;
}
try {
// public void updateAppPermission(Account account, String authTokenType, int uid, boolean value) {
Method updateAppPermissionMethod = AccountManager.class.getDeclaredMethod("updateAppPermission",
Account.class, String.class, int.class, boolean.class);
updateAppPermissionMethod.setAccessible(true);
updateAppPermissionMethod.invoke(accountManager, // Instance to invoke the method on
accountToRevoke, // account
"oauth2:https://www.googleapis.com/auth/somegoogleservice", // authTokenType
context.getApplicationInfo().uid, // uid
false); // false to revoke
} catch (Exception e) {
Log.w(TAG, "revokeAppPermission: Failed:" + e.getMessage());
e.printStackTrace();
return false;
}
return true;
}
खाता हटाएं और दोबारा जोड़ें, फिर अनुमति रद्द कर दी गई है ... यह गलत है! –
आप भगवान हैं। यह एकमात्र तरीका है जो एसओ पर देखने के बाद मेरे लिए काम करता है। धन्यवाद। – 0x4B1D