本文整理匯總了Java中android.accounts.AccountManager.peekAuthToken方法的典型用法代碼示例。如果您正苦於以下問題:Java AccountManager.peekAuthToken方法的具體用法?Java AccountManager.peekAuthToken怎麽用?Java AccountManager.peekAuthToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.accounts.AccountManager
的用法示例。
在下文中一共展示了AccountManager.peekAuthToken方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getAuthToken
import android.accounts.AccountManager; //導入方法依賴的package包/類
@Override
public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException
{
AccountManager accountManager = AccountManager.get(mContext);
String authToken = accountManager.peekAuthToken(account, authTokenType);
if (!authToken.isEmpty())
{
Bundle bundle = new Bundle();
bundle.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
bundle.putString(AccountManager.KEY_AUTHTOKEN, authToken);
return bundle;
}
return newAccount(response);
}
示例2: getAuthToken
import android.accounts.AccountManager; //導入方法依賴的package包/類
@Override
public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType,
Bundle options) throws NetworkErrorException {
final AccountManager am = AccountManager.get(context);
String authToken = am.peekAuthToken(account, authTokenType);
// get new token if there is no one
if (TextUtils.isEmpty(authToken)) {
String password = am.getPassword(account);
if (password != null) {
try {
password = Crypto.armorDecrypt(password, context);
authToken = serverHandler.userSignIn(account.name, password);
} catch (Exception e) {
e.printStackTrace();
}
}
}
// there is new token, return it
if (!TextUtils.isEmpty(authToken)) {
final Bundle result = new Bundle();
result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type);
result.putString(AccountManager.KEY_AUTHTOKEN, authToken);
return result;
}
// no token and no password, show login screen
final Intent intent = new Intent(context, loginActivity);
intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
intent.putExtra(GlobalConstant.ACCOUNT_TYPE, account.type);
intent.putExtra(GlobalConstant.ACCOUNT_NAME, account.name);
intent.putExtra(IS_ADDING_NEW_ACCOUNT, false);
final Bundle bundle = new Bundle();
bundle.putParcelable(AccountManager.KEY_INTENT, intent);
return bundle;
}