2010-08-29 77 views
5

我已经创建了一个应用程序发送带有录音的电子邮件,当意图被激发并选择电子邮件作为发送附件的应用程序时,您可以看到有一个附件,但附件未送达。Android的电子邮件意图不发送附件

Intent sendIntent = new Intent(Intent.ACTION_SEND); 
//Mime type of the attachment (or) u can use sendIntent.setType("*/*") 
sendIntent.setType("audio/3gp"); 
//Subject for the message or Email 
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "My Recording"); 
//Full Path to the attachment 
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(fileName)); 
//Use a chooser to decide whether email or mms 
startActivity(Intent.createChooser(sendIntent, "Send email...")); 

任何想法?

+0

我已经有了一个图像相同的问题,甚至在开始时使用“file://”。希望你找到了另一种方法来使它工作? – skamlet 2012-03-11 14:49:37

+1

我发现这个问题,我的文件是私人的,所以邮件应用程序无法读取文件。它现在工作正常 – skamlet 2012-03-11 17:11:48

+0

@ D4r7h你是如何使你的文件“不私密”? 'file.SetReadable(true);'? 我也尝试将文件移动到〜文件夹,但没有运气。我有一个正确发送的txt文件。 你能给我一个提示,请问? – 2016-03-25 15:18:47

回答

10

我想通了,你需要确保你的uri在它前面有“file://”。

0

从API级别24开始,不能使用“file://”URI在包之间传递文件。相反,您应该执行FileProvider并使用它传递文件。

Uri fileUri = FileProvider.getUriForFile(context, "com.yourdomain.yourapp.fileprovider", file); 

约FileProvides的好处是,你不需要WRITE_EXTERNAL_STORAGE许可(用于API等级21以上)。

关于another StackOverflow answer或该文档中的最佳描述。

相关问题