Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓可以';找不到方法removeAccount_Android - Fatal编程技术网

Android 安卓可以';找不到方法removeAccount

Android 安卓可以';找不到方法removeAccount,android,Android,根据本教程,我已经为我的应用程序实现了帐户 除了我尝试使用以下代码删除帐户外,实现的每个方面都非常有效: public void logout(View view) { // remove account and restart app stopService(new Intent(this, ServerSync.class)); Account account = AccountManager.get(this).getAccountsByType(Const

根据本教程,我已经为我的应用程序实现了帐户

除了我尝试使用以下代码删除帐户外,实现的每个方面都非常有效:

    public void logout(View view) {
    // remove account and restart app
    stopService(new Intent(this, ServerSync.class));
    Account account = AccountManager.get(this).getAccountsByType(Constants.ACCOUNT_TYPE)[0];
    final AccountManagerFuture<Bundle> future = AccountManager.get(this).removeAccount(account, this, new AccountManagerCallback<Bundle>() {
        @Override
        public void run(AccountManagerFuture<Bundle> future) {
            try {
                future.getResult();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                Intent intent = getBaseContext().getPackageManager()
                        .getLaunchIntentForPackage(getBaseContext().getPackageName());
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                finish();
                startActivity(intent);
            }
        }
    }, null);
}
应用程序崩溃了

我遵循了Android文档

我的应用程序具有正确的权限等。我甚至尝试在我的AccountAuthenticator中覆盖getAccountRemovalAllowed,强制它返回true


Android文档中是否缺少一些其他信息?

您正在使用的removeAccount版本是在api leve 22中引入的,您可能正在旧版本的Android上使用它。您应该在运行时检查当前版本,并对Android版本早于22的设备使用弃用版本的
removeAccount

if(Build.VERSION.SDK\u INT<22){
AccountManager.get(this).removeAccount(account,new AccountManager callback(){….},null)
}否则{
//您正在使用的版本
}
NoSuchMethodError: android.accounts.AccountManager.removeAccount
if (Build.VERSION.SDK_INT < 22) {
    AccountManager.get(this).removeAccount(account, new AccountManagerCallback<Bundle>(){....}, null) 
} else {
   // the version you are already using
}