Skip to content

Instantly share code, notes, and snippets.

@auycro
Last active July 15, 2016 01:16
Show Gist options
  • Save auycro/10c9632b5e2b800ceb3a4595cbc33865 to your computer and use it in GitHub Desktop.
Save auycro/10c9632b5e2b800ceb3a4595cbc33865 to your computer and use it in GitHub Desktop.
Android get user account email (but not work)
import android.accounts.AccountManager;
import android.accounts.Account;
public class GetAccountPlugin {
//CANNOT GET CORRECT PURCHASED USER'S EMAIL
public String GetGoogleAccountEmail(Activity activity){
AccountManager manager = (AccountManager) activity.getSystemService(Context.ACCOUNT_SERVICE);
Account[] accounts = manager.getAccounts();
//Log.d(tag, "GetGoogleAccountEmail-LENGTH " + accounts.length);
String strGmail = "";
for (Account account : accounts) {
String possibleEmail = account.name;
String type = account.type;
if (type.equals("com.google")) {
strGmail = possibleEmail;
//Log.d(tag, "GetGoogleAccountEmail-GMAIL " + strGmail);
break;
}
}
return strGmail;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment