Last active
July 15, 2016 01:16
-
-
Save auycro/10c9632b5e2b800ceb3a4595cbc33865 to your computer and use it in GitHub Desktop.
Android get user account email (but not work)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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