Java Code Examples for android.accounts.AccountManager#removeAccount()
The following examples show how to use
android.accounts.AccountManager#removeAccount() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: cathode File: Accounts.java License: Apache License 2.0 | 8 votes |
public static void removeAccount(Context context) { try { AccountManager am = AccountManager.get(context); Account account = getAccount(context); ContentResolver.removePeriodicSync(account, BuildConfig.PROVIDER_AUTHORITY, new Bundle()); ContentResolver.removePeriodicSync(account, BuildConfig.AUTHORITY_DUMMY_CALENDAR, new Bundle()); AccountAuthenticator.allowRemove(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { am.removeAccount(account, null, null, null); } else { am.removeAccount(account, null, null); } } catch (SecurityException e) { Timber.e(e, "Unable to remove account"); } }
Example 2
Source Project: TelePlus-Android File: ContactsController.java License: GNU General Public License v2.0 | 7 votes |
public void deleteUnknownAppAccounts() { try { systemAccount = null; AccountManager am = AccountManager.get(ApplicationLoader.applicationContext); Account[] accounts = am.getAccountsByType("org.telegram.messenger"); for (int a = 0; a < accounts.length; a++) { Account acc = accounts[a]; boolean found = false; for (int b = 0; b < UserConfig.MAX_ACCOUNT_COUNT; b++) { TLRPC.User user = UserConfig.getInstance(b).getCurrentUser(); if (user != null) { if (acc.name.equals("" + user.id)) { found = true; break; } } } if (!found) { try { am.removeAccount(accounts[a], null, null); } catch (Exception ignore) { } } } } catch (Exception e) { e.printStackTrace(); } }
Example 3
Source Project: RememBirthday File: AccountResolver.java License: GNU General Public License v3.0 | 6 votes |
/** * Remove account from Android system */ @SuppressWarnings("deprecation") public boolean removeAccount() { Log.d(getClass().getSimpleName(), "Removing account : " + account.name); AccountManager accountManager = AccountManager.get(context); // remove account AccountManagerFuture accountManagerFuture; if(android.os.Build.VERSION.SDK_INT < 23) { accountManagerFuture = accountManager.removeAccount(account, null, null); } else { accountManagerFuture = accountManager.removeAccount(account, null, null, null); } if (accountManagerFuture.isDone()) { try { accountManagerFuture.getResult(); return true; } catch (Exception e) { Log.e(getClass().getSimpleName(), "Problem while removing account!", e); return false; } } else { return false; } }
Example 4
Source Project: android-galaxyzoo File: LoginUtils.java License: GNU General Public License v3.0 | 6 votes |
/** Don't call this from the main UI thread. * * @param context */ public static void removeAccount(final Context context, final String accountName) { final AccountManager accountManager = AccountManager.get(context); final Account account = new Account(accountName, LoginUtils.ACCOUNT_TYPE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { //Trying to call this on an older Android version results in a //NoSuchMethodError exception. //There is no AppCompat version of the AccountManager API to //avoid the need for this version check at runtime. accountManager.removeAccount(account, null, null, null); } else { //noinspection deprecation //Note that this needs the MANAGE_ACCOUNT permission on //SDK <=22. //noinspection deprecation accountManager.removeAccount(account, null, null); } }
Example 5
Source Project: framework File: OdooAccountManager.java License: GNU Affero General Public License v3.0 | 6 votes |
/** * Remove account from device * * @param context * @param username * @return true, if account removed successfully */ public static boolean removeAccount(Context context, String username) { OUser user = getDetails(context, username); if (user != null) { AccountManager accountManager = AccountManager.get(context); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { if (accountManager.removeAccountExplicitly(user.getAccount())) { dropDatabase(user); } return true; } else { try { AccountManagerFuture<Boolean> result = accountManager. removeAccount(user.getAccount(), null, null); if (result.getResult()) { dropDatabase(user); } return true; } catch (OperationCanceledException | IOException | AuthenticatorException e) { e.printStackTrace(); } } } return false; }
Example 6
Source Project: indigenous-android File: TestUtils.java License: GNU General Public License v3.0 | 5 votes |
static void removeAccount(Context context, Activity activity) { User user = new Accounts(context).getDefaultUser(); AccountManager am = AccountManager.get(context); am.removeAccount(user.getAccount(), activity, null, null); SharedPreferences.Editor editor = context.getSharedPreferences("indigenous", MODE_PRIVATE).edit(); editor.putString("account", ""); editor.apply(); editor.commit(); }
Example 7
Source Project: TelePlus-Android File: ContactsController.java License: GNU General Public License v2.0 | 5 votes |
public void deleteUnknownAppAccounts() { try { systemAccount = null; AccountManager am = AccountManager.get(ApplicationLoader.applicationContext); Account[] accounts = am.getAccountsByType("org.telegram.messenger"); for (int a = 0; a < accounts.length; a++) { Account acc = accounts[a]; boolean found = false; for (int b = 0; b < UserConfig.MAX_ACCOUNT_COUNT; b++) { TLRPC.User user = UserConfig.getInstance(b).getCurrentUser(); if (user != null) { if (acc.name.equals("" + user.id)) { found = true; break; } } } if (!found) { try { am.removeAccount(accounts[a], null, null); } catch (Exception ignore) { } } } } catch (Exception e) { e.printStackTrace(); } }
Example 8
Source Project: Yahala-Messenger File: MessagesController.java License: MIT License | 5 votes |
public void deleteAllAppAccounts() { try { AccountManager am = AccountManager.get(ApplicationLoader.applicationContext); Account[] accounts = am.getAccountsByType("org.telegram.messenger.account"); for (Account c : accounts) { am.removeAccount(c, null, null); } } catch (Exception e) { e.printStackTrace(); } }
Example 9
Source Project: ETSMobile-Android2 File: ApplicationManager.java License: Apache License 2.0 | 5 votes |
public static void deconnexion(final Activity activity) { Editor editor = PreferenceManager.getDefaultSharedPreferences(activity).edit(); Editor secureEditor = new SecurePreferences(activity).edit(); editor.clear(); secureEditor.clear(); // Enlever le profil de la DB SQLite new ProfilManager(activity).removeProfil(); new NoteManager(activity).remove(); AccountManager accountManager = AccountManager.get(activity); Account[] accounts = accountManager.getAccountsByType(Constants.ACCOUNT_TYPE); for (int index = 0; index < accounts.length; index++) { accountManager.removeAccount(accounts[index], null, null); } ArnEndpointHandler handler = new ArnEndpointHandler(activity, "", "", ""); handler.deleteEndpoint(); editor.apply(); secureEditor.apply(); ApplicationManager.userCredentials = null; Intent intent = new Intent(activity, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); activity.startActivity(intent); new Thread(new Runnable() { @Override public void run() { activity.finish(); } }).start(); }
Example 10
Source Project: Woodmin File: WoodminSyncAdapter.java License: Apache License 2.0 | 5 votes |
public static void removeAccount(Context context){ String user = Utility.getPreferredUser(context); AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE); Account account = new Account("Woodmin", context.getString(R.string.sync_account_type)); if ( accountManager.getPassword(account) != null ) { String secret = Utility.getPreferredSecret(context); accountManager.removeAccount(account,null,null); } }
Example 11
Source Project: Woodmin File: WoodminSyncAdapter.java License: Apache License 2.0 | 5 votes |
public static void disablePeriodSync(Context context){ Log.e(LOG_TAG, "disablePeriodSync"); Account account = getSyncAccount(context); String authority = context.getString(R.string.content_authority); ContentResolver.cancelSync(account, authority); AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE); accountManager.removeAccount(account, null, null); }
Example 12
Source Project: palmsuda File: AuthenticationUtil.java License: Apache License 2.0 | 5 votes |
public synchronized static void deleteAccount(Context context) { AccountManager mAccountManager = AccountManager.get(context); Account[] mAccounts = mAccountManager .getAccountsByType(Constants.ACCOUNT_TYPE); if (mAccounts != null && mAccounts.length > 0) { for (Account account2 : mAccounts) { Log.d(TAG, "account2 name=" + account2.name); mAccountManager.removeAccount(account2, null, null); } } }
Example 13
Source Project: hr File: OdooAccountManager.java License: GNU Affero General Public License v3.0 | 5 votes |
/** * Remove account from device * * @param context * @param username * @return true, if account removed successfully */ public static boolean removeAccount(Context context, String username) { OUser user = getDetails(context, username); if (user != null) { AccountManager accountManager = AccountManager.get(context); accountManager.removeAccount(user.getAccount(), null, null); return true; } return false; }
Example 14
Source Project: Woodmin File: WoodminSyncAdapter.java License: Apache License 2.0 | 5 votes |
public static void removeAccount(Context context){ String user = Utility.getPreferredUser(context); AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE); Account account = new Account("Woodmin", context.getString(R.string.sync_account_type)); if ( accountManager.getPassword(account) != null ) { String secret = Utility.getPreferredSecret(context); accountManager.removeAccount(account,null,null); } }
Example 15
Source Project: Woodmin File: WoodminSyncAdapter.java License: Apache License 2.0 | 5 votes |
public static void disablePeriodSync(Context context){ Log.e(LOG_TAG, "disablePeriodSync"); Account account = getSyncAccount(context); String authority = context.getString(R.string.content_authority); ContentResolver.cancelSync(account, authority); AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE); accountManager.removeAccount(account, null, null); }
Example 16
Source Project: android-atleap File: AuthHelper.java License: Apache License 2.0 | 5 votes |
/** * Recreate account * @param account account * @param authTokenType authTokenType * @param requiredFeatures requiredFeatures, could be <code>null</code> * @param options options, could be <code>null</code> * @param activity activity (cannot be <code>null</code>) */ public static void reCreateAccount(Account account, String accountType, String authTokenType, String[] requiredFeatures, Bundle options, Activity activity) { if (activity == null) { throw new IllegalArgumentException("activity cannot be null"); } final AccountManager accountManager = AccountManager.get(activity.getApplicationContext()); if (isAccountExist(activity, account)) { accountManager.removeAccount(account, null, null); } accountManager.addAccount(accountType, authTokenType, requiredFeatures, options, activity, null, null); }
Example 17
Source Project: Telegram-FOSS File: ContactsController.java License: GNU General Public License v2.0 | 5 votes |
public void deleteUnknownAppAccounts() { try { systemAccount = null; AccountManager am = AccountManager.get(ApplicationLoader.applicationContext); Account[] accounts = am.getAccountsByType("org.telegram.messenger"); for (int a = 0; a < accounts.length; a++) { Account acc = accounts[a]; boolean found = false; for (int b = 0; b < UserConfig.MAX_ACCOUNT_COUNT; b++) { TLRPC.User user = UserConfig.getInstance(b).getCurrentUser(); if (user != null) { if (acc.name.equals("" + user.id)) { found = true; break; } } } if (!found) { try { am.removeAccount(accounts[a], null, null); } catch (Exception ignore) { } } } } catch (Exception e) { e.printStackTrace(); } }
Example 18
Source Project: Telegram File: ContactsController.java License: GNU General Public License v2.0 | 5 votes |
public void deleteUnknownAppAccounts() { try { systemAccount = null; AccountManager am = AccountManager.get(ApplicationLoader.applicationContext); Account[] accounts = am.getAccountsByType("org.telegram.messenger"); for (int a = 0; a < accounts.length; a++) { Account acc = accounts[a]; boolean found = false; for (int b = 0; b < UserConfig.MAX_ACCOUNT_COUNT; b++) { TLRPC.User user = UserConfig.getInstance(b).getCurrentUser(); if (user != null) { if (acc.name.equals("" + user.id)) { found = true; break; } } } if (!found) { try { am.removeAccount(accounts[a], null, null); } catch (Exception ignore) { } } } } catch (Exception e) { e.printStackTrace(); } }
Example 19
Source Project: cnode-android File: AccountUtils.java License: MIT License | 4 votes |
public static void cleanExistedAccounts(AccountManager accountManager) { for (Account account : accountManager.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE)) { accountManager.removeAccount(account, null, null); } }
Example 20
Source Project: android-atleap File: AuthHelper.java License: Apache License 2.0 | 2 votes |
/** * Remove specified account * @param context context * @param account account to remove */ public static void removeAccount(Context context, Account account) { final AccountManager accountManager = AccountManager.get(context); accountManager.removeAccount(account, null, null); }