Search code examples
androidgmail

Remove GMAIL Account programmatically


How to remove all GMAIL Accounts available in the Device, programmatically in Android? Does the app need to be a System app to do this?


Solution

  • You can use removeAccount() in AccountManager to attempt to remove the account. Note that this method is not guaranteed to remove the account.

    Additionally, the first Gmail account configured on the device is a sort of main Account, and I don't think you can completely remove it without a factory reset

    Edit , Code to Clear All GMAIL Password :

                AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
                Account[] accounts = accountManager.getAccounts();
                for (int index = 0; index < accounts.length; index++) {
                    accountManager.clearPassword(accounts[index]);
                }