Samuel V.Samsung SEAP Moderator
Jun 27, 2017
10:57 pm

Hi Akshay,

Unfortunately, we don't directly support the use case of removing a specific Google account.

But we do have APIs that:

1) Prevent the addition of a type/specific account:

private void preventAdditionOfGoogleAccount() {
    EnterpriseDeviceManager edm = (EnterpriseDeviceManager) getSystemService(EnterpriseDeviceManager.ENTERPRISE_POLICY_SERVICE);
    try {
        List<String> blackList = new ArrayList<String>();
        blackList.add(".*@gmail.com");
        // Supported account types can be retrieved from getSupoprtedAccountTypes()
        // For example supported Google account type will be "com.google"
        boolean success = edm.getDeviceAccountPolicy().addAccountsToAdditionBlackList("com.google", blackList);
        if (success) {
            Log.d(TAG, "Addition to blacklist is a success");
        } else {
            Log.d(TAG, "Addition to blacklist is a failure");
        }
    } catch (SecurityException e) {
        Log.w(TAG, "SecurityException: " + e);
    }
}

2) Remove all accounts of a certain type (ex. @google.com accounts):

 EnterpriseDeviceManager edm = (EnterpriseDeviceManager) getSystemService(EnterpriseDeviceManager.ENTERPRISE_POLICY_SERVICE);
  SecurityPolicy securityPolicy = edm.getSecurityPolicy();
  try {
      boolean result = securityPolicy.removeAccountsByType(
                                                     "com.google");
      if(true == result)
      {
          //account deleted successfully
      }
  }catch(SecurityException e) {
      Log.w(TAG,"SecurityException: "+e);
  }

Best regards,

Samuel