如何从AccountManager注销我自己的身份验证器?

问题描述:

我正在关注this question的回答。如何从AccountManager注销我自己的身份验证器?

但我得到这个错误:

java.lang.NoSuchMethodError: No virtual method removeAccount(Landroid/accounts/Account;Landroid/app/Activity;Landroid/accounts/AccountManagerCallback;Landroid/os/Handler;)Landroid/accounts/AccountManagerFuture; in class Landroid/accounts/AccountManager; or its super classes (declaration of 'android.accounts.AccountManager' appears in /system/framework/framework.jar).

如何注销正常吗?

public void logOut() { 
 
    final Account accounts[] = mAccountManager.getAccounts(); 
 

 
    if (accounts.length > 0) { 
 
     mAccountManager.removeAccount(accounts[0], (Activity) context, new AccountManagerCallback<Bundle>() { 
 
      @Override 
 
      public void run(AccountManagerFuture<Bundle> future) { 
 
       try { 
 
        Bundle bnd = future.getResult(); 
 
        Log.d(TAG, String.valueOf(bnd)); 
 
       } catch (Exception e) { 
 
        e.printStackTrace(); 
 
       } 
 
      } 
 
     }, null); 
 
    } 
 
}

我的解决办法如下。虽然它已被弃用,但它的工作原理。如果你更了解任何解决方案,我将不胜感激。

mAccountManager.removeAccount(account, new AccountManagerCallback<Boolean>() { 
 
       @Override 
 
       public void run(AccountManagerFuture<Boolean> future) { 
 
        try { 
 
         if (future.getResult()) { 
 
          // do something 
 
         } 
 
        } catch (Exception e) { 
 
         e.printStackTrace(); 
 
        } 
 

 
       } 
 
      }, null);