Account[] accounts = AccountManager.get(context).getAccounts();
我正在使用上面的代码从oreo +设备的电话中获取用户帐户详细信息。有什么更好的方法,以便我可以获得用户帐户的邮件ID,尤其是Gmail / Play商店ID?
答案 0 :(得分:0)
我以前遇到过这个问题,请参阅一些博客和开发人员指南,您可以尝试以下方法:
Intent googlePicker = AccountManager.newChooseAccountIntent(null, null,
new String[] { "com.google"}, true, null, null, null, null);
startActivityForResult(googlePicker, PICK_ACCOUNT_REQUEST);
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
if (requestCode == PICK_ACCOUNT_REQUEST && resultCode == RESULT_OK) {
String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
Log.d(TAG, "Account Name=" + accountName);
String accountType = data.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE);
Log.d(TAG, "Account type=" + accountType);
AccountManager accountManager = AccountManager.get(this);
Account[] accounts = accountManager.getAccounts();
for (Account a : accounts) {
//获取信息
}
}
}
您可以看到