當前位置: 首頁>>代碼示例>>Java>>正文


Java AccountManager.getAuthToken方法代碼示例

本文整理匯總了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;
    }
 
開發者ID:tiberiusteng,項目名稱:financisto1-holo,代碼行數:38,代碼來源:FlowzrSyncTask.java

示例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;
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:27,代碼來源:AndroidAuthenticator.java


注:本文中的android.accounts.AccountManager.getAuthToken方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。