gpt4 book ai didi

java - Android AccountManager.getUserData() 返回 null

转载 作者:太空宇宙 更新时间:2023-11-03 11:39:32 24 4
gpt4 key购买 nike

我有类似的问题AccountManager getUserData returning null despite it being set但是这些解决方案对我不起作用

我的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;
}

}

我添加了一个这样的帐户

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

但是当我尝试通过调用 getUserData() 获取用户数据时,我得到的是 null

最佳答案

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

不要使用 addAccountExplicitly(Account, String, Bundle) 添加用户数据.相反,只需传递一个空包并使用 setUserData(Account, String, String)在您使用 addAccountExplicitly 创建帐户后 添加用户数据。

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

关于java - Android AccountManager.getUserData() 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28691847/

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