java - 通过电子邮件客户端从具有多个文本文件的应用程序发送电子邮件的代码问题
问题描述
我正在尝试使用应用程序内的电子邮件客户端发送一封包含用户输入的多个文本字段的电子邮件。
当我通过模拟器或我的 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 :"));
}
});
}
}
解决方案
我认为您只能向EXTRA_TEXT
意图发送一个。您可以做的是将您需要的字符串合并为一个并将其发送到那里,否则您可以使用EXTRA_HTML_TEXT
see here
推荐阅读
- generics - 在 kotlin 中,测试泛型类型的值是否实现接口,然后将其用作该接口的正确方法是什么?
- amazon-web-services - S3 网站可以访问 API Gateway 私有端点吗?
- python - 无法编码对象:
pymongo - javascript - 通过 Bootstrap 类更改 Div 的大小时不会触发 CSS 过渡
- sql - 如何从当前周、月或年的第一天到当前日期获取周、月或年的日期?
- php - fwrite 的参数文件名导致错误权限被拒绝
- node.js - 如何在 vscode 调试器中调试多个节点项目?
- android - 我可以在 Firebase 中设置“差异推送接收设置”吗?
- android - 将 UTC 时间戳转换为本地时间戳
- html - 不规则的表格 div