本文整理汇总了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;
}