2010-08-29 73 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或該文檔中的最佳描述。

相關問題