Java Code Examples for android.accounts.AccountManager#removeAccount()

The following examples show how to use android.accounts.AccountManager#removeAccount() . 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 File: ContactsController.java    From TelePlus-Android with GNU General Public License v2.0 7 votes vote down vote up
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 2
Source File: Accounts.java    From cathode with Apache License 2.0 7 votes vote down vote up
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 3
Source File: AccountResolver.java    From RememBirthday with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 File: OdooAccountManager.java    From framework with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 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 5
Source File: LoginUtils.java    From android-galaxyzoo with GNU General Public License v3.0 6 votes vote down vote up
/** 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 6
Source File: ContactsController.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
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 7
Source File: ContactsController.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
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 File: AuthHelper.java    From android-atleap with Apache License 2.0 5 votes vote down vote up
/**
 * 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 9
Source File: WoodminSyncAdapter.java    From Woodmin with Apache License 2.0 5 votes vote down vote up
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 10
Source File: WoodminSyncAdapter.java    From Woodmin with Apache License 2.0 5 votes vote down vote up
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 File: OdooAccountManager.java    From hr with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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 12
Source File: AuthenticationUtil.java    From palmsuda with Apache License 2.0 5 votes vote down vote up
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 File: WoodminSyncAdapter.java    From Woodmin with Apache License 2.0 5 votes vote down vote up
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 14
Source File: WoodminSyncAdapter.java    From Woodmin with Apache License 2.0 5 votes vote down vote up
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 File: ApplicationManager.java    From ETSMobile-Android2 with Apache License 2.0 5 votes vote down vote up
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 16
Source File: MessagesController.java    From Yahala-Messenger with MIT License 5 votes vote down vote up
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 17
Source File: ContactsController.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
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 File: TestUtils.java    From indigenous-android with GNU General Public License v3.0 5 votes vote down vote up
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 19
Source File: AccountUtils.java    From cnode-android with MIT License 4 votes vote down vote up
public static void cleanExistedAccounts(AccountManager accountManager) {
    for (Account account : accountManager.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE)) {
        accountManager.removeAccount(account, null, null);
    }
}
 
Example 20
Source File: AuthHelper.java    From android-atleap with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}