在四处寻找之后,我终于下载了所有相关的应用程序(outlook、linkedin、twitter..)并使用以下代码转储了帐户类型:
public void pickUserAccount() {
/*This will list all available accounts on device without any filtering*/
Intent intent = AccountPicker.newChooseAccountIntent(null, null,
null, false, null, null, null, null);
startActivityForResult(intent, REQUEST_CODE_PICK_ACCOUNT);
}
/*After manually selecting every app related account, I got its Account type using the code below*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_PICK_ACCOUNT) {
// Receiving a result from the AccountPicker
if (resultCode == RESULT_OK) {
System.out.println(data.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE));
System.out.println(data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME));
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, R.string.pick_account, Toast.LENGTH_LONG).show();
}
}
}
这是我得到的以下结果:
- Outlook(Hotmail,实时):
com.outlook.Z7.eas
- 领英:
com.linkedin.android
- Facebook:
com.facebook.auth.login
- 推特:
com.twitter.android.auth.login
- Android Mail 应用程序中使用的所有其他 Imap 电子邮件帐户:(
com.google.android.legacyimap
感谢 Ozbek)
- 当然还有谷歌:
com.google
我仍然缺少雅虎帐户类型,导致雅虎邮件应用程序在我的设备上不断崩溃。
所以希望各位有雅虎账号类型的请分享一下。
2015 年 7 月 12 日修订版,提供更好的解决方案
Pattern emailPattern = Patterns.EMAIL_ADDRESS;
Account[] accounts = AccountManager.get(getActivity()).getAccounts();
ArrayList<String> emails = new ArrayList<String>();
for (Account account : accounts) {
if (emailPattern.matcher(account.name).matches()) {
emails.add(account.name);
}
}