get Account Token - Android Account

Android examples for Account:Account Information

Description

get Account Token

Demo Code


//package com.java2s;
import java.io.IOException;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.content.Context;

public class Main {
    public static final String LETV_ACCOUNT_TYPE = "com.letv";

    public static String getAccountToken(Context context)
            throws OperationCanceledException, IOException,
            AuthenticatorException {//  ww w  . jav a 2 s  . c o  m
        AccountManager am = AccountManager.get(context);
        final Account[] accountList = am
                .getAccountsByType(LETV_ACCOUNT_TYPE);
        String authToken = null;
        if (accountList != null && accountList.length > 0) {
            authToken = am.blockingGetAuthToken(accountList[0],
                    LETV_ACCOUNT_TYPE, true);
        }
        return authToken;
    }
}

Related Tutorials