我是Android新手,但最近遇到了问题。 在按下登录按钮时,AccountManager将填写帐户详细信息,如下所示。
AccountManager mAccountManager;
final Account account = new Account(mUsername, Constant.ACCOUNT_TYPE);
mAccountManager.addAccountExplicitly(account, token, null);
ContentResolver.setSyncAutomatically(account,
ContactsContract.AUTHORITY, true);
但是在我按下或在我重新启动应用程序后,我希望从以下位置查看帐户详细信息:
accountManager = AccountManager.get(applicationController.getCurrentActivity());
accounts = accountManager.getAccountsByType(packageName);
帐户返回[0],即没有任何内容。 请帮帮我。
onAuthenticationResult(string,string)函数调用finishlogin,它存储帐户信息
public void onAuthenticationResult(String error, String token) {
// Hide the progress dialog
// hideProgress();
if (token != null && !"".equalsIgnoreCase(token)) {
{
finishLogin(token);
CommonMethods.getInstance().showAppMsg(
"Registered Successfully.");
}
}
这里是finishLogin函数,它接受一个令牌并将其存储在帐户管理器中,并带有用户名
protected void finishLogin(String token) {
account = new Account(mUsername, Constant.ACCOUNT_TYPE);
if (mRequestNewAccount) {
mAccountManager.addAccountExplicitly(account, token, null);
// Set contacts sync for this account.
ContentResolver.setSyncAutomatically(account,
ContactsContract.AUTHORITY, true);
} else {
mAccountManager.setPassword(account, mUsername);
}
if (Constant.isCampaign) {
keyarr = new String[] { "token", "imei", "deviceid", "osversion",
"modal", "screen_width", "screen_height", "manufacturer",
"simcountrycode", "simoperator", "phonetype",
"networktype", "gcmregid", "device_type", "app_version",
"download_source", "api_version" };
valuearr = new String[] { token, imei, androidId,
String.valueOf(softwareversion), PhoneModel,
String.valueOf(divwidth), String.valueOf(divheight),
PhoneMANUFACTURER, simcountrycode, simoperator, phonetype,
networktype, Constant.NEWGCM_REGD_ID, "ANDROID",
"" + Constant.version, "" + Constant.DOWNLOAD_SOURCE,
"" + Constant.API_VERSION };
} else {
keyarr = new String[] { "token", "imei", "deviceid", "osversion",
"modal", "screen_width", "screen_height", "manufacturer",
"simcountrycode", "simoperator", "phonetype",
"networktype", "gcmregid", "device_type", "app_version",
"api_version" };
valuearr = new String[] { token, imei, androidId,
String.valueOf(softwareversion), PhoneModel,
String.valueOf(divwidth), String.valueOf(divheight),
PhoneMANUFACTURER, simcountrycode, simoperator, phonetype,
networktype, Constant.NEWGCM_REGD_ID, "ANDROID",
"" + Constant.version, "" + Constant.API_VERSION };
}
signUpScreenModel.WriteDeviceInfo(keyarr, valuearr);
applicationController.handleEvents(
ApplicationEvents.EVENT_ID_HOME_FRAGMENT, false);
}
答案 0 :(得分:0)
如果返回true,则必须在onResume()方法中检查登录主活动的帐户,您应该加载数据,其他建议需要完整代码。