Android AccountManager.getUserData()返回null [英] Android AccountManager.getUserData() returns null

查看:213
本文介绍了Android AccountManager.getUserData()返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似的问题,如 AccountManager getUserData返回null尽管它正在设置但解决方案对我不起作用

I have a similar problem like this AccountManager getUserData returning null despite it being set But the solutions did not work for me

My Authenticator.java

My Authenticator.java

public class Authenticator extends AbstractAccountAuthenticator{

    private Context context;
    public Authenticator(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public Bundle editProperties(AccountAuthenticatorResponse response,
            String accountType) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Bundle addAccount(AccountAuthenticatorResponse response,
            String accountType, String authTokenType,
            String[] requiredFeatures, Bundle options)
            throws NetworkErrorException {
        Bundle result = new Bundle();
        Intent intent = new Intent(context,LoginActivity.class);
        intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, accountType);
        intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
        result.putParcelable(AccountManager.KEY_INTENT, intent);
        return result;
    }

    @Override
    public Bundle confirmCredentials(AccountAuthenticatorResponse response,
            Account account, Bundle options) throws NetworkErrorException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Bundle getAuthToken(AccountAuthenticatorResponse response,
            Account account, String authTokenType, Bundle options)
            throws NetworkErrorException {

        return null;
    }

    @Override
    public String getAuthTokenLabel(String authTokenType) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Bundle updateCredentials(AccountAuthenticatorResponse response,
            Account account, String authTokenType, Bundle options)
            throws NetworkErrorException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Bundle hasFeatures(AccountAuthenticatorResponse response,
            Account account, String[] features) throws NetworkErrorException {

        return null;
    }

}

我添加了一个这样的帐户

I added an account like this

mAccount = new Account("SalesGenie", "com.ambertag.salesgenie.ACCOUNT"); 
mAccountManager.addAccountExplicitly(mAccount, password, userData);

但是当我尝试通过调用获取用户数据时getUserData()我得到了空白

But when I try to get user data by calling getUserData() I get null

推荐答案

有一个更简单的解决方案:

There is a much simpler solution:

请勿使用 addAccountExplicitly(Account,String,Bundle) 。相反,只需传递一个空包并使用 setUserData(帐户,字符串,字符串) 在您创建之后添加用户数据帐户 addAccountExplicitly

Don't add the user-data with addAccountExplicitly(Account, String, Bundle). Instead, just pass an empty bundle and use setUserData(Account, String, String) to add the user-data after you created the account with addAccountExplicitly.

它可能不太方便,但它会确保用户 - 数据缓存已正确填充,不会返回 null

It may be a little less convenient, but it will make sure that the user-data cache is populated properly and won't return null.

这篇关于Android AccountManager.getUserData()返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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