Ruben Nellikunnathu Ruben Nellikunnathu - 1 year ago 269
Android Question

Getting the Gmail Id of the User In Android 6.0 marshmallow

I am getting email id by using


try {
Account[] accounts = AccountManager.get(this).getAccountsByType("");
for (Account account : accounts) {
emailid =;
} catch (Exception e) {
Log.i("Exception", "Exception:" + e);

This code is working on all devices upto Lollipop 5.1.
But its not working in Marshmallow 6.0.

Can anyone help me to resolve this problem.
I am not even getting any errors in logcat.

Answer Source

This code is working, Tested on Android 4.4.4, 5.0.1, 6.0 and 6.0.1

String possibleEmail = "";
    final Account[] accounts = AccountManager.get(context).getAccounts();
    for (Account account : accounts) {
        if (Patterns.EMAIL_ADDRESS.matcher( {
            possibleEmail =;

possibleEmail is the email of the device.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download