Get Configured Email Address From Android Device Programmatically

In java code need the following piece of code.

String gmail = null;

    Pattern gmailPattern = Patterns.EMAIL_ADDRESS; // API level 8+

    Account[] accounts = AccountManager.get(this).getAccounts();

    for (Account account : accounts) {

        if (gmailPattern.matcher(account.name).matches()) {

            gmail = account.name;

        }

    }

    Log.d(“gmail”, gmail+“**”);

And also need permission in AndroidManifest.xml

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s