Example usage for android.accounts AccountManager blockingGetAuthToken

List of usage examples for android.accounts AccountManager blockingGetAuthToken

Introduction

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

Prototype

public String blockingGetAuthToken(Account account, String authTokenType, boolean notifyAuthFailure)
        throws OperationCanceledException, IOException, AuthenticatorException 

Source Link

Document

This convenience helper synchronously gets an auth token with #getAuthToken(Account,String,boolean,AccountManagerCallback,Handler) .

Usage

From source file:org.opendatakit.sync.aggregate.AggregateSynchronizer.java

public String updateAccessToken() throws InvalidAuthTokenException {
    AccountManager accountManager = AccountManager.get(context);
    try {/* w ww  .j ava2  s  .  c  om*/
        SyncPreferences prefs = new SyncPreferences(context, appName);
        Account account = new Account(prefs.getAccount(), ACCOUNT_TYPE_G);
        this.accessToken = accountManager.blockingGetAuthToken(account, authString, true);
        return accessToken;
    } catch (Exception e) {
        e.printStackTrace();
        throw new InvalidAuthTokenException("unable to update access token -- please re-authorize");
    }
}