Android:如何以编程方式获取配置的电子邮件帐户地址

Android:如何以编程方式获取配置的电子邮件帐户地址

问题描述:

我使用下面的代码来获取配置的帐户名

I used the below code to get the configured account name

Account[] accounts = AccountManager.get(this).getAccounts();
        for (Account account : accounts) {

        Log.d("Account", "Name " + account.name);

        }

但我需要配置的Microsoft Exchange 帐户电子邮件ID,因为我们可以更改帐户名称(不必是唯一的).

But i need the email id of the configured Microsoft Exchange account as we can change the name of the account (it is not need to be unique).

提前致谢

此代码正常运行

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 
                                  *************

";
               Account[] accounts =  
           AccountManager.get(this).getAccountsByType("com.google");

               for (Account account : accounts) {

                 possibleEmail += " --> "+account.name+" : "+account.type+" , 
";
                 possibleEmail += " 

";

               }
          }
          catch(Exception e)
          {
               Log.i("Exception", "Exception:"+e) ; 
          }


          try{
               possibleEmail += "**************** Get All Registered Accounts 
                      *****************

";

               Account[] accounts = AccountManager.get(this).getAccounts();
               for (Account account : accounts) {

                  possibleEmail += " --> "+account.name+" : "+account.type+" , 
";
                  possibleEmail += " 
";

               }
          }
          catch(Exception e)
          {
               Log.i("Exception", "Exception:"+e) ; 
          }

       // Show on screen    
       accountsData.setText(possibleEmail);

       Log.i("Exception", "mails:"+possibleEmail) ;
     }
}