本文整理匯總了Java中android.accounts.AccountManager.getAuthToken方法的典型用法代碼示例。如果您正苦於以下問題:Java AccountManager.getAuthToken方法的具體用法?Java AccountManager.getAuthToken怎麽用?Java AccountManager.getAuthToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.accounts.AccountManager
的用法示例。
在下文中一共展示了AccountManager.getAuthToken方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: work
import android.accounts.AccountManager; //導入方法依賴的package包/類
protected Object work(Context context, DatabaseAdapter dba, String... params) throws ImportExportException {
AccountManager accountManager = AccountManager.get(context);
android.accounts.Account[] accounts = accountManager.getAccountsByType("com.google");
String accountName=MyPreferences.getFlowzrAccount(context);
if (accountName == null) {
NotificationManager nm = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context,
FlowzrSyncActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
Builder mNotifyBuilder = new NotificationCompat.Builder(context);
mNotifyBuilder
.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.icon)
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setContentTitle(context.getString(R.string.flowzr_sync))
.setContentText(
context.getString(R.string.flowzr_choose_account));
nm.notify(0, mNotifyBuilder.build());
Log.i("Financisto","account name is null");
throw new ImportExportException(R.string.flowzr_choose_account);
}
Account useCredential = null;
for (int i = 0; i < accounts.length; i++) {
if (accountName.equals(((android.accounts.Account) accounts[i]).name)) {
useCredential=accounts[i];
}
}
accountManager.getAuthToken(useCredential, "ah", false, new GetAuthTokenCallback(), null);
return null;
}
示例2: getAuthToken
import android.accounts.AccountManager; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
@Override
public String getAuthToken() throws AuthFailureError {
final AccountManager accountManager = AccountManager.get(mContext);
AccountManagerFuture<Bundle> future = accountManager.getAuthToken(mAccount,
mAuthTokenType, mNotifyAuthFailure, null, null);
Bundle result;
try {
result = future.getResult();
} catch (Exception e) {
throw new AuthFailureError("Error while retrieving auth token", e);
}
String authToken = null;
if (future.isDone() && !future.isCancelled()) {
if (result.containsKey(AccountManager.KEY_INTENT)) {
Intent intent = result.getParcelable(AccountManager.KEY_INTENT);
throw new AuthFailureError(intent);
}
authToken = result.getString(AccountManager.KEY_AUTHTOKEN);
}
if (authToken == null) {
throw new AuthFailureError("Got null auth token for type: " + mAuthTokenType);
}
return authToken;
}