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

标签 android email account email-client accountmanager

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

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/

相关文章:

android - index.html 未在移动浏览器上加载 style.css(离线,保存在文件夹中)

java - 来自 URL 的文件名不包含文件名后缀

Android - 使用 Retrofit 解析没有数组标题的 JSON

java - android 延迟加载图库问题

android - 如何在android中创建忘记密码?

Android Material Drawer 删除帐户标题下拉列表

php - Woocommerce "My Account" "Address Field"显示

html - 电子邮件 html 中的 Alt、标题和其他标记

发送电子邮件后 Android View 为空

ios - iOS 开发者计划上的多个帐户