Search in sources :

Example 61 with AccountManager

use of android.accounts.AccountManager in project android-delicious by lexs.

the class DeliciousAccount method get.

public static DeliciousAccount get(Context context) {
    AccountManager accountManager = AccountManager.get(context.getApplicationContext());
    Account[] accounts = accountManager.getAccountsByType(Constants.ACCOUNT_TYPE);
    if (accounts.length > 0) {
        return new DeliciousAccount(context, accountManager, accounts[0]);
    } else {
        return null;
    }
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager)

Example 62 with AccountManager

use of android.accounts.AccountManager in project iosched by google.

the class LoginUtils method setFirstAvailableAccountAsActive.

/**
     *
     * @return account name, or a test account name
     */
public static String setFirstAvailableAccountAsActive(Context context) {
    String account;
    AccountManager am = AccountManager.get(InstrumentationRegistry.getTargetContext());
    Account[] accountArray = am.getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
    if (accountArray.length > 0) {
        account = accountArray[0].name;
    } else {
        account = DUMMY_ACCOUNT_NAME;
    }
    AccountUtils.setActiveAccount(InstrumentationRegistry.getTargetContext(), account);
    return account;
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager)

Example 63 with AccountManager

use of android.accounts.AccountManager in project iosched by google.

the class AndroidAuthenticator method getAuthToken.

// TODO: Figure out what to do about notifyAuthFailure
@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;
}
Also used : Bundle(android.os.Bundle) AuthFailureError(com.android.volley.AuthFailureError) AccountManager(android.accounts.AccountManager) Intent(android.content.Intent)

Example 64 with AccountManager

use of android.accounts.AccountManager in project MWM-for-Android-Gen1 by MetaWatchOpenProjects.

the class Utils method getGoogleAccountName.

public static String getGoogleAccountName(Context context) {
    AccountManager accountManager = AccountManager.get(context);
    Account[] accounts = accountManager.getAccounts();
    int count = accounts.length;
    Account account = null;
    for (int i = 0; i < count; i++) {
        account = accounts[i];
        if (account.type.equals("com.google")) {
            return account.name;
        }
    }
    return "";
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager)

Example 65 with AccountManager

use of android.accounts.AccountManager in project Notes by MiCode.

the class GTaskClient method loginGoogleAccount.

private String loginGoogleAccount(Activity activity, boolean invalidateToken) {
    String authToken;
    AccountManager accountManager = AccountManager.get(activity);
    Account[] accounts = accountManager.getAccountsByType("com.google");
    if (accounts.length == 0) {
        Log.e(TAG, "there is no available google account");
        return null;
    }
    String accountName = NotesPreferenceActivity.getSyncAccountName(activity);
    Account account = null;
    for (Account a : accounts) {
        if (a.name.equals(accountName)) {
            account = a;
            break;
        }
    }
    if (account != null) {
        mAccount = account;
    } else {
        Log.e(TAG, "unable to get an account with the same name in the settings");
        return null;
    }
    // get the token now
    AccountManagerFuture<Bundle> accountManagerFuture = accountManager.getAuthToken(account, "goanna_mobile", null, activity, null, null);
    try {
        Bundle authTokenBundle = accountManagerFuture.getResult();
        authToken = authTokenBundle.getString(AccountManager.KEY_AUTHTOKEN);
        if (invalidateToken) {
            accountManager.invalidateAuthToken("com.google", authToken);
            loginGoogleAccount(activity, false);
        }
    } catch (Exception e) {
        Log.e(TAG, "get auth token failed");
        authToken = null;
    }
    return authToken;
}
Also used : Account(android.accounts.Account) Bundle(android.os.Bundle) AccountManager(android.accounts.AccountManager) ClientProtocolException(org.apache.http.client.ClientProtocolException) JSONException(org.json.JSONException) NetworkFailureException(net.micode.notes.gtask.exception.NetworkFailureException) IOException(java.io.IOException) ActionFailureException(net.micode.notes.gtask.exception.ActionFailureException)

Aggregations

AccountManager (android.accounts.AccountManager)105 Account (android.accounts.Account)76 Bundle (android.os.Bundle)14 IOException (java.io.IOException)11 Intent (android.content.Intent)10 OperationCanceledException (android.accounts.OperationCanceledException)7 AuthenticatorException (android.accounts.AuthenticatorException)5 View (android.view.View)5 TextView (android.widget.TextView)5 HashSet (java.util.HashSet)5 SharedPreferences (android.content.SharedPreferences)4 AccountManagerCallback (android.accounts.AccountManagerCallback)3 Paint (android.graphics.Paint)3 JSONException (org.json.JSONException)3 AccountsException (android.accounts.AccountsException)2 TargetApi (android.annotation.TargetApi)2 AlertDialog (android.app.AlertDialog)2 Context (android.content.Context)2 DialogInterface (android.content.DialogInterface)2 OperationApplicationException (android.content.OperationApplicationException)2