Android 如何使用电子邮件客户端发送电子邮件?

Android 如何使用电子邮件客户端发送电子邮件?,android,Android,我正在努力- 获取我自己的主要电子邮件 将主电子邮件设置为收件人的地址,以便我可以发送电子邮件 对我自己 这就是我获取主要电子邮件的方式- Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+ Account[] accounts = AccountManager.get(getBaseContext()) .getAccounts();

我正在努力-

  • 获取我自己的主要电子邮件

  • 将主电子邮件设置为收件人的地址,以便我可以发送电子邮件 对我自己

  • 这就是我获取主要电子邮件的方式-

    Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
                Account[] accounts = AccountManager.get(getBaseContext())
                        .getAccounts();
                for (Account account : accounts) {
                    if (emailPattern.matcher(account.name).matches()) {
                        String possibleEmail = account.name;
                        Toast.makeText(this, possibleEmail, Toast.LENGTH_LONG)
                                .show();
                    }
                }
    
    这就是我发送电子邮件的方式-

    Intent i = new Intent(Intent.ACTION_SEND);
                i.setType("message/rfc822");
                i.putExtra(Intent.EXTRA_EMAIL,
                        new String[] { "recipient@example.com" });
                i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
                i.putExtra(Intent.EXTRA_TEXT, "body of email");
                try {
                    startActivity(Intent.createChooser(i, "Send mail..."));
                } catch (android.content.ActivityNotFoundException ex) {
                    Toast.makeText(Main.this,
                            "There are no email clients installed.",
                            Toast.LENGTH_SHORT).show();
                }
    
    如何给我的主要电子邮件发送额外的电子邮件?

    解决方案:

        String possibleEmail = null;
        Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
        Account[] accounts = AccountManager.get(getBaseContext())
                .getAccounts();
        for (Account account : accounts) {
            if (emailPattern.matcher(account.name).matches()) {
                possibleEmail = account.name;
                Toast.makeText(this, possibleEmail, Toast.LENGTH_LONG)
                        .show();
            }
        }
    
        Intent i = new Intent(Intent.ACTION_SEND);
        i.setType("message/rfc822");
        i.putExtra(Intent.EXTRA_EMAIL, new String[]{possibleEmail});
        i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
        i.putExtra(Intent.EXTRA_TEXT, "body of email");
        try {
            startActivity(Intent.createChooser(i, "Send mail..."));
        } catch (android.content.ActivityNotFoundException ex) {
            Toast.makeText(Main.this,
                    "There are no email clients installed.",
                    Toast.LENGTH_SHORT).show();
        }
    

    您需要至少对语言有基本的了解,因为如果您想在该区域存档某些内容,仅复制粘贴编程是非常糟糕的方式。请注意,
    AccountManager
    不需要为用户提供可用的电子邮件地址。@Divers太糟糕了,我是一名运动员,我这么做只是因为我需要音乐和spotify的作品。我正在制作一个应用程序,通过电子邮件将我的spotify个人资料保存下来,以后我可以获得无限的免费试用,并检索这个保存的个人资料,这样我就不会丢失我的播放列表了。@joey那么最好还是雇人吧someone@Divers我不需要它,我已经制作了应用程序:DD