Android Studio电子邮件意图。打开电子邮件客户端时填写收件人字段

时间:2017-04-28 20:26:22

标签: java email android-intent sendto

我对java很新,我遇到了电子邮件意图问题。我正在开发一个应用程序,我制作了一个电子邮件意图,但我不知道如何确保收件人字段不是用户输入在编辑文本框中的结果,我希望删除所以它只显示& #34;主体"和"消息"应用程序中的框。当您点按"发送"时,我希望收件人字段已填满。这是我的代码

 editTextSubject=(EditText)findViewById(R.id.editText2);
    editTextMessage=(EditText)findViewById(R.id.editText3);

    send=(Button) findViewById(R.id.button1);

    send.setOnClickListener(new View.OnClickListener(){

        @Override
        public void onClick(View arg0) {

            String[] recipients = new String[]{"email@gmail.com"};
            String subject=editTextSubject.getText().toString();
            String message=editTextMessage.getText().toString();





            Intent email = new Intent(Intent.ACTION_SEND);
            email.putExtra(Intent.EXTRA_EMAIL, recipients );
            email.putExtra(Intent.EXTRA_SUBJECT, subject);
            email.putExtra(Intent.EXTRA_TEXT, message);

            email.setType("message/rfc822");
            startActivity(Intent.createChooser(email,"Choose an Email client :"));

1 个答案:

答案 0 :(得分:0)

这里是我用来发送新电子邮件的代码

   public void contact() {
            final Intent send = new Intent(Intent.ACTION_SENDTO);

            final String email = "youremail@gmail.com";
            final String subject = "subject";
            final String body = "body...";

            final String uriText = "mailto:" + Uri.encode(email) +
                    "?subject=" + Uri.encode(subject) +
                    "&body=" + Uri.encode(body);
            final Uri uri = Uri.parse(uriText);

            send.setData(uri);
            startActivity(Intent.createChooser(send, getString(R.string.settings_email_chooser)));
        }