AccountManager.get(context).removeAccount(accounts[selection], null, null, null); } else { AccountManager.get(context).removeAccount(accounts[selection], null, null);
@Test public void testNavigationDrawerClickListenerPos5_ShouldLogoutUser() { mainActivity.onNavigationItemSelected(getMockMenuItem(R.id.navigation_log_out, "Logout")); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { verify(AccountManagerShadow.mockManager, times(2)).removeAccount(argumentCaptor.capture(), eq(mainActivity), anyObject(), anyObject()); } else { verify(AccountManagerShadow.mockManager, times(2)).removeAccount(argumentCaptor.capture(), anyObject(), anyObject()); } List<Account> values = argumentCaptor.getAllValues(); assertThat(values.get(0), is(equalTo(AccountManagerShadow.accounts[0]))); assertThat(values.get(1), is(equalTo(AccountManagerShadow.accounts[1]))); }
@Test public void testVoteNoAccount() { ShadowAccountManager.get(RuntimeEnvironment.application) .removeAccount(account, null, null); UserServices.Callback callback = mock(UserServices.Callback.class); assertFalse(userServices.voteUp(RuntimeEnvironment.application, "1", callback)); verify(call, never()).enqueue(any(Callback.class)); }
@Test public void testSubmitNoAccount() { ShadowAccountManager.get(RuntimeEnvironment.application) .removeAccount(account, null, null); UserServices.Callback callback = mock(UserServices.Callback.class); userServices.submit(RuntimeEnvironment.application, "title", "content", true, callback); verify(call, never()).enqueue(any(Callback.class)); verify(callback).onDone(eq(false)); }
private void logout() { // Remove cookies so that the login is clean if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { CookieManager.getInstance().removeAllCookies(null); } else { CookieManager.getInstance().removeAllCookie(); } // Clear all of the cached data CacheHelper helper = new CacheHelper(this); helper.getWritableDatabase().delete("orgs", null, null); helper.getWritableDatabase().delete("users", null, null); helper.getWritableDatabase().delete("repos", null, null); // Remove the account AccountManager accountManager = getAccountManager(); String accountType = getString(R.string.account_type); Account[] allGitHubAccounts = accountManager.getAccountsByType(accountType); for (Account account : allGitHubAccounts) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { accountManager.removeAccount(account, this, bool -> startLoginActivity(), null); } else { accountManager.removeAccount(account, bundle -> startLoginActivity(), null); } } }
@Test public void removeAccount_doesNotNotifyIfUnuccessful() { Account account = new Account("name", "type"); TestOnAccountsUpdateListener listener = new TestOnAccountsUpdateListener(); am.addOnAccountsUpdatedListener(listener, null, false); assertThat(listener.getInvocationCount()).isEqualTo(0); // The account has not been added am.removeAccount(account, null, null); assertThat(listener.getInvocationCount()).isEqualTo(0); }
@Test public void removeAccount_does() throws Exception { Account account = new Account("name", "type"); shadowOf(am).addAccount(account); TestAccountManagerCallback<Boolean> testAccountManagerCallback = new TestAccountManagerCallback<>(); AccountManagerFuture<Boolean> future = am.removeAccount(account, testAccountManagerCallback, null); assertThat(future.getResult()).isTrue(); assertThat(am.getAccountsByType("type")).isEmpty(); assertThat(testAccountManagerCallback.accountManagerFuture).isNotNull(); }
@Test public void removeAccount_notifiesListenersIfSuccessful() { Account account = new Account("name", "type"); am.addAccountExplicitly(account, "passwd", null); TestOnAccountsUpdateListener listener = new TestOnAccountsUpdateListener(); am.addOnAccountsUpdatedListener(listener, null, false); assertThat(listener.getInvocationCount()).isEqualTo(0); am.removeAccount(account, null, null); assertThat(listener.getInvocationCount()).isEqualTo(1); }
@Test public void removeAccount_throwsIllegalArgumentException_whenPassedNullAccount() { Account account = new Account("name", "type"); shadowOf(am).addAccount(account); try { am.removeAccount(null, null, null); fail("removeAccount() should throw an illegal argument exception if the account is null"); } catch (IllegalArgumentException iae) { // Expected } }
@Test public void removeAccount_doesNotRemoveAccountOfDifferentName() throws Exception { Account account = new Account("name", "type"); shadowOf(am).addAccount(account); Account wrongAccount = new Account("wrong_name", "type"); AccountManagerFuture<Boolean> future = am.removeAccount(wrongAccount, null, null); assertThat(future.getResult()).isFalse(); assertThat(am.getAccountsByType("type")).isNotEmpty(); }
// Global Variables public static final String AUTHORITY = "com.example.package"; public static final String ACCOUNT_TYPE = "com.example.package"; public static final String ACCOUNT = "my_custom_account_name"; // Account Manager definition AccountManager accountManager = (AccountManager) this.getSystemService(ACCOUNT_SERVICE); // loop through all accounts to remove them Account[] accounts = accountManager.getAccounts(); for (int index = 0; index < accounts.length; index++) { if (accounts[index].type.intern() == AUTHORITY) accountManager.removeAccount(accounts[index], null, null); }
final AccountManager accountManager = AccountManager.get(getContext()); final String accountType = AuthenticatorService.ACCOUNT_TYPE; final Account[] availableAccounts = accountManager.getAccountsByType(accountType); for (final Account availableAccount : availableAccounts) { final AccountManagerFuture<Boolean> booleanAccountManagerFuture = accountManager.removeAccount(availableAccount, null, null); assertTrue("Impossible to delete existing account for this application", booleanAccountManagerFuture.getResult(1, TimeUnit.SECONDS)); }
AccountManager am = AccountManager.get(this); Account[] accounts = am.getAccounts(); if (accounts.length > 0) { Account accountToRemove = accounts[0]; am.removeAccount(accountToRemove, null, null); }
public static void removeAccount(Context context){ AccountManager am = AccountManager.get(context); Account[] localAccounts = am.getAccounts(); for (int i=0; i<localAccounts.length; i++){ if (localAccounts[i].type.equals("com.facebook.auth.login")){ am.removeAccount(localAccounts[i], null, null); } } }
@Override public void onClick(View v) { // Clic on Remove Button accountManager.removeAccount(myAccount, null, null); Toast.makeText(getApplicationContext(), "Account has been removed", Toast.LENGTH_LONG).show(); finish();//finishing activity } };
private static void removeOldAccounts(android.accounts.AccountManager am, Collection<android.accounts.Account> accountsToRemove) { if (!accountsToRemove.isEmpty()) { MyLog.i(TAG, "Removing " + accountsToRemove.size() + " old accounts"); for (android.accounts.Account account : accountsToRemove) { MyLog.i(TAG, "Removing old account: " + account.name); am.removeAccount(account, null, null); } } } }
AccountManager mgr = AccountManager.get(getApplicationContext()); mgr.invalidateAuthToken(AUTHORITY , null); Account[] accounts = mgr.getAccounts(); for (int index = 0; index < accounts.length; index++) { if (accounts[index].type.intern() == AUTHORITY) mgr.removeAccount(accounts[index], null, null); }
private void tearDownAccount() { if (!getAccounts().isEmpty()) { Account account = getAccounts().get(0); getAccountManager().removeAccount(account, this, null); } else { tearDownActivity(); } }
private void tearDownAccount() { if (!getAccounts().isEmpty()) { Account account = getAccounts().get(0); getAccountManager().removeAccount(account, this, null); } else { tearDownActivity(); } }
private void onRemoveAccount() { StateOfAccountChangeProcess state = ((AccountSettingsActivity) getActivity()).getState(); if (state.builder.isPersistent()) { for (android.accounts.Account account : MyAccounts.getAccounts(getActivity())) { if (state.getAccount().getAccountName().equals(account.name)) { MyLog.i(this, "Removing account: " + account.name); android.accounts.AccountManager am = AccountManager.get(getActivity()); am.removeAccount(account, getActivity(), null, null); } } getActivity().finish(); } }