要在安卓手机上的电子邮件中附加JSON文件,可以使用以下代码示例:
private void sendEmailWithAttachment(String email, String subject, String message, String filePath) {
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("*/*");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { email });
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, message);
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + filePath));
startActivity(Intent.createChooser(emailIntent, "选择邮件应用"));
}
String email = "example@example.com";
String subject = "附件测试";
String message = "这是一个附加JSON文件的测试邮件";
String filePath = "/sdcard/example.json";
sendEmailWithAttachment(email, subject, message, filePath);
请注意,要附加JSON文件,您需要提供正确的文件路径。在上面的示例中,我们使用/sdcard/example.json
作为文件路径。根据您的情况,您可能需要更改文件路径。
此代码将打开用户的电子邮件应用程序,并自动填充电子邮件地址,主题,消息和附加的JSON文件。用户只需选择发送即可。
希望这可以帮助您解决问题!