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

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

问题描述

我是新来的android.accounts的API,现在我试图做一些与他们,但出现得体哑问题...结果
I`ve创建一个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.

现在我希望做这个方法有些简单的事情,写codeS如下:

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(帐号,密码为空);
这有什么错呢?

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?

后来补充:
异常的系统进程。系统将崩溃。
NullPointerException异常被抛出的AccountManager。
看来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的一个bug。结果
如果您添加帐户到的AccountManager,你的必须的也提供了SynAdapter的帐号,在Android 2.0平台下。但事情都是正确的Andr​​oid下的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://$c$c.google.com/p /安卓/问题/细节?ID = 5009 结果
和结果
<一href=\"http://stackoverflow.com/questions/3085242/accountmanager-without-a-syncadapter\">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天全站免登陆