Example usage for android.accounts AccountManager updateCredentials

List of usage examples for android.accounts AccountManager updateCredentials

Introduction

In this page you can find the example usage for android.accounts AccountManager updateCredentials.

Prototype

public AccountManagerFuture<Bundle> updateCredentials(final Account account, final String authTokenType,
        final Bundle options, final Activity activity, final AccountManagerCallback<Bundle> callback,
        final Handler handler) 

Source Link

Document

Asks the user to enter a new password for an account, updating the saved credentials for the account.

Usage

From source file:com.hemou.android.account.AccountUtils.java

/**
 * Update account//from   w w  w  .  j  a  v a2  s. c  o  m
 * 
 * @param account
 * @param act
 * @return true if account was updated, false otherwise
 */
public static boolean updateAccount(final Account account, final Activity act) {
    if (act == null)
        throw new IllegalArgumentException("Activity cannot be null");
    final String SUB_TAG = "acnt_update";
    int count = UPDATE_COUNT.get();
    synchronized (UPDATE_COUNT) {
        // Don't update the account if the account was successfully updated
        // while the lock was being waited for
        if (count != UPDATE_COUNT.get())
            return true;

        AccountManager manager = AccountManager.get(act);
        try {
            if (!hasAuthenticator(manager))
                throw new AuthenticatorConflictException();
            manager.updateCredentials(account, AUTHTOKEN_TYPE, null, act, null, null).getResult();
            UPDATE_COUNT.incrementAndGet();
            return true;
        } catch (OperationCanceledException e) {
            Log.d(SUB_TAG, "Excepting retrieving account", e);
            act.finish();
            return false;
        } catch (AccountsException e) {
            Log.d(SUB_TAG, "Excepting retrieving account", e);
            return false;
        } catch (AuthenticatorConflictException e) {
            act.runOnUiThread(new Runnable() {

                public void run() {
                    showConflictMessage(act);
                }
            });
            return false;
        } catch (IOException e) {
            Log.d(SUB_TAG, "Excepting retrieving account", e);
            return false;
        }
    }
}