使用 android.accounts 身份验证器的问题 [英] Problem using android.accounts Authenticator

查看:23
本文介绍了使用 android.accounts 身份验证器的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 android.accounts apis 的新手,现在我正在尝试用它们做一些事情,但出现了一个看似虚拟的问题......
我为我的应用程序创建了一个身份验证器,但尚未实现抽象方法.它的图标成功出现在系统的Add a Account窗口中,我知道当我点击它时,就会调用Authenticator中的addAccount方法.

I'm new to the android.accounts apis, and now I'm trying to do something with them but a seemly dummy problem occurs...
I`ve created an Authenticator for my app but did not yet implement the abstract methods. The icon of it successfully appears in the system Add a Account window, and I know that when I click it, the method addAccount in the Authenticator will be invoked.

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

Now I wish to do some simple thing in this method, and write codes below:

    @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 的演示,并且做出了类似的动作.但是我通过直接添加帐户来练习使用这些 API.但是系统崩溃了 manager.addAccountExplicitly(account, password, null);有什么问题吗?

I've seen the demo of SampleSyncAdapter, and make moves like it. But I practice using these APIs by directly adding an account. But system crashed by the line manager.addAccountExplicitly(account, password, null); What's wrong with it?

后来补充:系统进程异常.系统会崩溃.AccountManager 抛出 NullPointerException.似乎是 addAccountExplicitly 方法的问题,当我评论这条语句时,没有发生崩溃.

Added later: Exception in system process. System will crash. NullPointerException throw by AccountManager. It seems the problem of the addAccountExplicitly method, as I comment this statement no crash happen.

推荐答案

我已经解决了.

事实证明这是Android 2.0中的一个错误.
如果您在 AccountManager 中添加一个帐户,则在 Android 2.0 平台下,您还必须为该帐户提供一个 SynAdapter.但是在Android 2.1 及更高版本下一切正常.

It turns out that it's a bug in Android 2.0.
If you add an account to the AccountManager, you must also provide a SynAdapter to the account, under the Android 2.0 platform. But things are all right under Android 2.1 and above.

这是一个已知问题,请参考:
http://code.google.com/p/android/issues/详细信息?id=5009

AccountManager 没有 SyncAdapter?

This is a known issue, please refer to:
http://code.google.com/p/android/issues/detail?id=5009
and
AccountManager without a SyncAdapter?

这篇关于使用 android.accounts 身份验证器的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆