fedormoore
fedormoore

Reputation: 15

how to get a list of accounts

Please tell me how I get a list of all accounts. but I only get google accounts I have permission.

Thread myThread = new Thread(
    new Runnable() {
        public void run() {
            try {
                GoogleAuthUtil.requestGoogleAccountsAccess(getApplicationContext());
            } catch (Exception e) {
                if (e instanceof UserRecoverableAuthException) {
                    startActivityForResult(((UserRecoverableAuthException)
                    e).getIntent(), MY_PERMISSIONS_REQUEST_READ_CONTACTS);
                } else {
                    Log.e("SignIn", "Exception in getting google accounts" + e);
                }
            }
        }
   });
myThread.start();

AccountManager manager = AccountManager.get(this);
Account[] list = manager.getAccounts();
for (Account account : list) {
    possibleEmail += " --> "+account.name+" : "+account.type+" , n";
    possibleEmail += " n";
}

Upvotes: 0

Views: 181

Answers (1)

Mayur Coceptioni
Mayur Coceptioni

Reputation: 443

  <uses-permission android:name="android.permission.GET_ACCOUNTS" />

  Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
  Account[] accounts = AccountManager.get(context).getAccounts();
   for (Account account : accounts) {
    if (emailPattern.matcher(account.name).matches()) {
     String possibleEmail = account.name;
    ...
   }
 }

Upvotes: 0

Related Questions