Something like this should work:
AccountManager manager = (AccountManager) getSystemService(ACCOUNT_SERVICE);
Account[] list = manager.getAccounts();
String gmail = null;
for(Account account: list)
{
if(account.type.equalsIgnoreCase("com.google"))
{
gmail = account.name;
break;
}
}
And you will need the following permission in your manifest:
<uses-permission android:name="android.permission.GET_ACCOUNTS"></uses-permission>
Remember to 'Requesting Permissions at Run Time' if you support Android 6 and later
https://developer.android.com/training/permissions/requesting.html
I wrote this from memory so it may need a little tweaking. Apparently it's possible to register now without an email address, so maybe do some regexing on the data to ensure it's actually an email address (ensure it contains @gmail or @googlemail)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…