0
在我的應用程序中有第一次啓動時顯示的註冊表活動。
我希望用戶不必輸入他們的郵件和/或用戶名。我想獲取他們的郵件和/或姓名,並將其發送到我的服務器應用程序以在那裏註冊。
我怎樣才能得到這些信息?用於自動註冊碼的Android使用設備(谷歌)賬戶郵件
在我的應用程序中有第一次啓動時顯示的註冊表活動。
我希望用戶不必輸入他們的郵件和/或用戶名。我想獲取他們的郵件和/或姓名,並將其發送到我的服務器應用程序以在那裏註冊。
我怎樣才能得到這些信息?用於自動註冊碼的Android使用設備(谷歌)賬戶郵件
您可以使用AccountManager來獲得所有谷歌賬戶。
public String getAccountsName(){
AccountManager manager = AccountManager.get(this);
Account[] accounts = manager.getAccountsByType("com.google");
List<String> possibleEmails = new LinkedList<String>();
for (Account account : accounts) {
// TODO: Check possibleEmail against an email regex or treat
// account.name as an email address only for certain account.type values.
possibleEmails.add(account.name);
}
if(!possibleEmails.isEmpty() && possibleEmails.get(0) != null){
String email = possibleEmails.get(0);
String[] parts = email.split("@");
if(parts.length > 0 && parts[0] != null)
return parts[0];
else
return null;
}else
return null;
}