gpt4 book ai didi

android - 使用 android.accounts 身份验证器时出现问题

转载 作者:行者123 更新时间:2023-11-29 02:13:10 25 4
gpt4 key购买 nike

我是 android.accounts api 的新手,现在我想用它们做点什么,但出现了一个看似虚拟的问题......
我已经为我的应用程序创建了一个 Authenticator,但还没有实现抽象方法。它的图标成功出现在系统的Add a Account窗口中,我知道当我点击它时,会调用Authenticator中的addAccount方法。

现在我想在这个方法中做一些简单的事情,代码如下:

    @Override
public Bundle addAccount(AccountAuthenticatorResponse response,
String accountType, String authTokenType, String[] requiredFeatures,
Bundle options) {

Log.d(LOG_TAG, "RRAuthenticator add account... ");
String accountName = "example@example.com";
Account account = new Account(accountName, accountType);
String password = "example_password";
AccountManager manager = AccountManager.get(context);
manager.addAccountExplicitly(account, password, null);

Bundle bundle = new Bundle();
bundle.putString(AccountManager.KEY_ACCOUNT_NAME, accountName);
bundle.putString(AccountManager.KEY_ACCOUNT_TYPE, accountType);
bundle.putString(AccountManager.KEY_AUTHTOKEN, "example_authtoken");
return bundle;
}

我看过SampleSyncAdapter 的demo,也跟着做了。但是我通过直接添加一个帐户来练习使用这些API。但是系统因行 manager.addAccountExplicitly(account, password, null); 而崩溃有什么问题吗?


稍后添加:系统进程异常。系统会崩溃。AccountManager 抛出 NullPointerException。这似乎是 addAccountExplicitly 方法的问题,因为我评论此语句没有发生崩溃。

最佳答案

我已经解决了。

原来是Android 2.0的bug。
如果您向 AccountManager 添加一个帐户,您必须还为该帐户提供一个 SynAdapter,在 Android 2.0 平台下。但在Android 2.1及以上版本下一切正常。

这是一个已知问题,请引用:
http://code.google.com/p/android/issues/detail?id=5009

AccountManager without a SyncAdapter?

关于android - 使用 android.accounts 身份验证器时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6057405/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com