public static String getUserToken(Context context, Account account) { AccountManager manager = AccountManager.get(context); return manager.getUserData(account, AccountManager.KEY_AUTHTOKEN); } }
/** * Get configured account * * @param context * @return account or null if none */ public static Account getAccount(final Context context) { final Account[] accounts = AccountManager.get(context) .getAccountsByType(ACCOUNT_TYPE); return accounts.length > 0 ? accounts[0] : null; }
private AccountManager getAccountManager() { return AccountManager.get(this); } }
@SuppressLint("MissingPermission") public static Pair<String, String> getCredentials(Context context) { String username = Preferences.getUsername(context); if (TextUtils.isEmpty(username)) { return null; } AccountManager accountManager = AccountManager.get(context); Account[] accounts = accountManager.getAccountsByType(BuildConfig.APPLICATION_ID); for (Account account : accounts) { if (TextUtils.equals(username, account.name)) { return Pair.create(username, accountManager.getPassword(account)); } } return null; }
@Config(sdk = 21) @Test public void testRemoveAccount() { AccountManager.get(activity).addAccountExplicitly(new Account("existing", BuildConfig.APPLICATION_ID), "password", null); Preferences.setUsername(activity, "existing"); drawerAccount.performClick(); AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog(); assertNotNull(alertDialog); assertThat(alertDialog.getListView().getAdapter()).hasCount(1); alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL).performClick(); assertThat(alertDialog).isNotShowing(); assertThat(AccountManager.get(activity).getAccounts()).isEmpty(); }
/** * Get default account where password can be retrieved * * @param context * @return password accessible account or null if none */ public static Account getPasswordAccessibleAccount(final Context context) { AccountManager manager = AccountManager.get(context); Account[] accounts = manager.getAccountsByType(ACCOUNT_TYPE); if (accounts == null || accounts.length == 0) { return null; } try { accounts = getPasswordAccessibleAccounts(manager, accounts); } catch (AuthenticatorConflictException e) { return null; } return accounts != null && accounts.length > 0 ? accounts[0] : null; }
/** * Creates a new authenticator. * @param context Context for accessing AccountManager * @param account Account to authenticate as * @param authTokenType Auth token type passed to AccountManager * @param notifyAuthFailure Whether to raise a notification upon auth failure */ public AndroidAuthenticator(Context context, Account account, String authTokenType, boolean notifyAuthFailure) { this(AccountManager.get(context), account, authTokenType, notifyAuthFailure); }
public static String getUserAvatar(Context context, Account account) { AccountManager manager = AccountManager.get(context); return manager.getUserData(account, USER_PIC); }
@SuppressLint("MissingPermission") private void showLogin() { Account[] accounts = AccountManager.get(this) .getAccountsByType(BuildConfig.APPLICATION_ID); if (accounts.length == 0) { // no accounts, ask to login or re-login startActivity(new Intent(this, LoginActivity.class)); } else { // has accounts, show account chooser regardless of login status AppUtils.showAccountChooser(this, mAlertDialogBuilder, accounts); } }
/** * Creates a new authenticator. * @param context Context for accessing AccountManager * @param account Account to authenticate as * @param authTokenType Auth token type passed to AccountManager * @param notifyAuthFailure Whether to raise a notification upon auth failure */ public AndroidAuthenticator(Context context, Account account, String authTokenType, boolean notifyAuthFailure) { this(AccountManager.get(context), account, authTokenType, notifyAuthFailure); }
public static String getUserName(Context context, Account account) { AccountManager manager = AccountManager.get(context); return manager.getUserData(account, USER_NAME); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.login); clientId = getString(R.string.github_client); secret = getString(R.string.github_secret); redirectUri = getString(R.string.github_oauth); accountManager = AccountManager.get(this); Account[] accounts = accountManager.getAccountsByType(getString(R.string.account_type)); if (accounts.length > 0) { openMain(); } checkOauthConfig(); }
/** * Creates a new authenticator. * @param context Context for accessing AccountManager * @param account Account to authenticate as * @param authTokenType Auth token type passed to AccountManager * @param notifyAuthFailure Whether to raise a notification upon auth failure */ public AndroidAuthenticator(Context context, Account account, String authTokenType, boolean notifyAuthFailure) { this(AccountManager.get(context), account, authTokenType, notifyAuthFailure); }
public static String getUserMail(Context context, Account account) { AccountManager manager = AccountManager.get(context); return manager.getUserData(account, USER_MAIL); }
@Provides @Singleton public AccountManager provideAccountManager(Context context) { return AccountManager.get(context); } }
public static String getUrl(Context context, Account account) { AccountManager manager = AccountManager.get(context); return manager.getUserData(account, USER_URL); }
public GoogleHandle(Activity act, String type, String email){ if(AQuery.ACTIVE_ACCOUNT.equals(email)){ email = getActiveAccount(act); } this.act = act; this.type = type.substring(2); this.email = email; this.am = AccountManager.get(act); }
@Test public void testGet() { assertThat(am).isNotNull(); assertThat(am).isSameAs(AccountManager.get(ApplicationProvider.getApplicationContext())); AccountManager activityAM = AccountManager.get(ApplicationProvider.getApplicationContext()); assertThat(activityAM).isNotNull(); assertThat(activityAM).isSameAs(am); }
@Before public void setUp() throws Exception { am = AccountManager.get(ApplicationProvider.getApplicationContext()); scheduler = Robolectric.getForegroundThreadScheduler(); activity = new Activity(); }
@Test public void testRemoveAccount() { Preferences.setUsername(context, "olduser"); AppUtils.registerAccountsUpdatedListener(context); shadowOf(AccountManager.get(context)).addAccount( new Account("newuser", BuildConfig.APPLICATION_ID)); assertNull(Preferences.getUsername(context)); Preferences.setUsername(context, "newuser"); shadowOf(AccountManager.get(context)).addAccount( new Account("olduser", BuildConfig.APPLICATION_ID)); assertEquals("newuser", Preferences.getUsername(context)); }