Getting the Gmail Id of the User In Android

user2568702 picture user2568702 · Sep 4, 2013 · Viewed 10.2k times · Source

I don't know it is the correct question or not.How can we get the lo-gin id of the user from which it has been lo-gin to the Google Play Store in Android.Is this possible or not.

Answer

Auto-Droid ツ picture Auto-Droid ツ · Sep 4, 2013

As per my knowledge the user has to configure his gmail account in his android phone and then he gets access to Google Play.

You can fetch the account information as given below (from Jim Blackler):

import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Context;

/**
* This class uses the AccountManager to get the primary email address of the
* current user.
*/
public class UserEmailFetcher {

    static String getEmail(Context context) {
        AccountManager accountManager = AccountManager.get(context); 
        Account account = getAccount(accountManager);

        if (account == null) {
            return null;
        } else {
            return account.name;
        }
    }

    private static Account getAccount(AccountManager accountManager) {
        Account[] accounts = accountManager.getAccountsByType("com.google");
        Account account;
        if (accounts.length > 0) {
            account = accounts[0];      
        } else {
            account = null;
        }
        return account;
    }
}

In Manifest

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