android - 电子邮件中的附件

标签 android android-intent email-attachments

我正在开发一个需要向某人发送电子邮件的应用程序。除了附件,一切正常。这是一段代码

 emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(  "file://"+Environment.getExternalStorageDirectory()+""+attach));

附件是我在手机里浏览得到的文件。 但附件未发送请帮助。

谢谢

最佳答案

根据我的博文找到here :

Creating a mail on Android which the user may send with the app of his choice is widely spread on the net. But it isn't how you attach a file which will be send by googlemail.

The problem here is that the gmail app only want to send files which are located on the sdcard

Intent mail = new Intent(android.content.Intent.ACTION_SEND);
mail.setType("application/octet-stream");
mail.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {"my@mail.com"});
mail.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
mail.putExtra(android.content.Intent.EXTRA_TEXT, "Message");
mail.putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse("file://" + Environment.getExternalStorageDirectory().getAbsolutePath() + "/file.txt"));
PrefAct.startActivity(Intent.createChooser(mail, "Send mail via..."));

As said gmail will refuse your attachment when the user sends the mail when the file isn't located on the ExternalStorage.

关于android - 电子邮件中的附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9332893/

相关文章:

java - 在接收器类中使用上下文

java - 如何在android中创建后台服务?

c# - 我可以发送图像和 rar 文件,但这些文件已被 asp.net 损坏?

Python:打开 Thunderbird 以编写带有附件的新邮件

android - 如何在我的程序中间停止 Intent Service?

php - 解码从android发布的base64图像数据以将图像保存在php服务器上

Android DatePicker 监听器未触发

android - 如何自定义带有彩色项目背景的ListView?

parsing - 正则表达式用于在纯文本电子邮件中查找内嵌图像

android - 为什么我们的 Android 2.2 应用程序 "incompatible"与 Android 2.3.5