Java tutorial
//package com.java2s; //License from project: Apache License import android.accounts.Account; import android.accounts.AccountManager; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.text.TextUtils; public class Main { /** * Invalidate auth token for specified account * @param account account to invalidate auth token * @param authTokenType auth token type * @param requiredFeatures requiredFeatures, could be <code>null</code> * @param options options, could be <code>null</code> * @param activity activity (cannot be <code>null</code>) */ public static void invalidateAuthToken(Account account, String authTokenType, String[] requiredFeatures, Bundle options, Activity activity) { if (activity == null) { throw new IllegalArgumentException("activity cannot be null"); } if (account == null) { throw new IllegalArgumentException("account cannot be null"); } Context context = activity.getApplicationContext(); final AccountManager am = AccountManager.get(context); String authToken = am.peekAuthToken(account, authTokenType); if (!TextUtils.isEmpty(authToken)) { am.invalidateAuthToken(account.type, authToken); } am.addAccount(account.type, authTokenType, requiredFeatures, options, activity, null, null); } /** * Add account * @param accountType accountType * @param authTokenType authTokenType * @param requiredFeatures requiredFeatures, could be <code>null</code> * @param options options, could be <code>null</code> * @param activity activity (cannot be <code>null</code>) */ public static void addAccount(String accountType, String authTokenType, String[] requiredFeatures, Bundle options, Activity activity) { if (activity == null) { throw new IllegalArgumentException("activity cannot be null"); } final AccountManager accountManager = AccountManager.get(activity.getApplicationContext()); accountManager.addAccount(accountType, authTokenType, requiredFeatures, options, activity, null, null); } }