-2

Now I am doing a android project. The project needs to get the default username and password of Android phone.

I don't know how to get the default gmail information of one Android Cell Phone. Can u help me. Thanks.

Sahil Mahajan Mj
  • 11,033
  • 8
  • 53
  • 100
ZHAO Xiaojian
  • 207
  • 3
  • 4
  • 7

2 Answers2

3

You should read about AccountManager to login using the gmail user but you will not get the username and password.

Macarse
  • 91,829
  • 44
  • 175
  • 230
1
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;
        ...
    }
}

Note that this requires the GET_ACCOUNTS permission:

vipin
  • 41
  • 9