2013-04-16 31 views
0

我將附加的文件,但他們表現出作爲一個(0字節) 下面的代碼是我用如何將jpeg文件附加到android中的郵件?

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
emailIntent.setType("image/jpeg"); 
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "ToDoNot.es"); 
emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(message)); 
File save_Image; 
File temp=null; 
save_Image=new File(ToDoViewActivity.this.getFilesDir(),"todofile"); 
temp=new File(save_Image,"tempfile"+String.valueOf(values.getAsInteger("rowid"))+".jpg"); 
Uri U = Uri.fromFile(new File("file://"+temp.getPath())); 
emailIntent.putExtra(Intent.EXTRA_STREAM,U); 
startActivity(Intent.createChooser(emailIntent, "Send email using")); 

outpur: enter image description here

回答

0

我也遇到過這個問題 - 問題在於您嘗試從應用程序的內部文件目錄中附加文件,而電子郵件意向沒有權限訪問它。

先將其複製到「外部」存儲,然後將其附加到電子郵件。這應該工作得很好。

0

你不鍵入文件類型...也許是因爲這個。

save_Image=new File(.........................."todofile.jpg") 
0

問題可能與的getPath呼叫的臨時文件有關。檢查調用的返回值,並確保您傳遞給putExtra構建的URI相匹配的這些文獻中記載的樣式之一:

Trying to attach a file from SD Card to email

https://superuser.com/questions/352133/what-is-the-reason-that-file-urls-start-with-three-slashes-file-etc

最值得注意的是,在文件後需要3個斜槓:。此外,但不太可能,您的問題可能是由您設置的MIME類型造成的,其中setType

相關問題