首页 > 解决方案 > 通过电子邮件客户端从具有多个文本文件的应用程序发送电子邮件的代码问题

问题描述

我正在尝试使用应用程序内的电子邮件客户端发送一封包含用户输入的多个文本字段的电子邮件。

当我通过模拟器或我的 Android 设备启动应用程序时,Android 不会打开电子邮件客户端。

我对此非常业余,并且正在玩。

public class send_page extends AppCompatActivity {

    Button sendbutton;
    EditText textdescribe;
    EditText textcause;
    EditText textcorrective;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_send_page);

            Button sendbutton = (Button) findViewById(R.id.send_button);
            textdescribe = (EditText) findViewById(R.id.describe);
            textcause = (EditText) findViewById(R.id.cause);
            textcorrective = (EditText) findViewById(R.id.corrective_actions);

            sendbutton.setOnClickListener(new View.OnClickListener() {


                @Override
                public void onClick(View v) {

                    String[] TO = {"email address"};
                    String[] SUBJECT = {"Near Miss Report"};
                    String description = textdescribe.getText().toString();
                    String causefactor = textcause.getText().toString();
                    String action = textcorrective.getText().toString();

                    Intent email = new Intent(Intent.ACTION_SEND);
                    email.putExtra(Intent.setData(Uri.parse("mailto:"));

                    email.putExtra(Intent.EXTRA_EMAIL, new String[]{"email address"});
                    email.putExtra(Intent.EXTRA_TEXT, description);
                    email.putExtra(Intent.EXTRA_TEXT, causefactor);
                    email.putExtra(Intent.EXTRA_TEXT, action);


                    email.setType("message/rfc822");

                    startActivity(Intent.createChooser(email, "Choose an Email client :"));



                }
            });
        }
    }

标签: javaandroidemail

解决方案


我认为您只能向EXTRA_TEXT意图发送一个。您可以做的是将您需要的字符串合并为一个并将其发送到那里,否则您可以使用EXTRA_HTML_TEXTsee here


推荐阅读