我使用下面的代码来获取配置的账户名
Account[] accounts = AccountManager.get(this).getAccounts();
for (Account account : accounts) {
Log.d("Account", "Name " + account.name);
}
但我需要已配置的 Microsoft Exchange 帐户 的电子邮件 ID,因为我们可以更改帐户名称(不需要是唯一的)。
提前致谢
最佳答案
这段代码可以正常工作
public class RegisteredEmailAccounts extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.registered_email_account);
final TextView accountsData = (TextView) findViewById(R.id.accounts);
String possibleEmail="";
try{
possibleEmail += "************* Get Registered Gmail Account
*************\n\n";
Account[] accounts =
AccountManager.get(this).getAccountsByType("com.google");
for (Account account : accounts) {
possibleEmail += " --> "+account.name+" : "+account.type+" , \n";
possibleEmail += " \n\n";
}
}
catch(Exception e)
{
Log.i("Exception", "Exception:"+e) ;
}
try{
possibleEmail += "**************** Get All Registered Accounts
*****************\n\n";
Account[] accounts = AccountManager.get(this).getAccounts();
for (Account account : accounts) {
possibleEmail += " --> "+account.name+" : "+account.type+" , \n";
possibleEmail += " \n";
}
}
catch(Exception e)
{
Log.i("Exception", "Exception:"+e) ;
}
// Show on screen
accountsData.setText(possibleEmail);
Log.i("Exception", "mails:"+possibleEmail) ;
}
}
关于Android:如何以编程方式获取配置的电子邮件帐户地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19449209/