2012-04-02 62 views
0

我有這封電子郵件發送代碼,不顯示選擇器(好)。如何擴展它以包含文件附件,而不涉及選擇器?如何將附件添加到電子郵件?

// Based on http://stackoverflow.com/questions/3312438 
final Intent intent = new Intent(Intent.ACTION_VIEW); 
final Uri data = Uri.parse("mailto:[email protected]?subject=My Sugbject&body="); 
intent.setData(data); 
startActivity(intent); 

回答

0

試試這個:

Intent emailintent = new Intent(android.content.Intent.ACTION_SEND); 
emailintent.setType("image/jpeg"); 
emailintent.putExtra(android.content.Intent.EXTRA_TEXT, 
"email body here"); 
emailintent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] 
    {"[email protected]"}); 
emailintent.putExtra(android.content.Intent.EXTRA_SUBJECT, 
"Subject here"); 
String filName="file:///sdcard/photos/estdemo.jpg"; 
emailintent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:/"+ filName)); 
this.startActivity(emailintent); 
+0

謝謝伊姆蘭。試了一下,但得到了一個有幾個選項的選擇器。我的問題是如何添加附件而不添加選擇器。 – user1139880 2012-04-03 02:50:39

0

嘗試下面的代碼,

Intent i = new Intent(Intent.ACTION_SEND); 
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
i.setType("image/jpg"); 
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("photo.jpg")); 
startActivity(i); 
+0

感謝路西法。試過它,但得到了與Picasa,消息等長選擇器 – user1139880 2012-04-03 02:49:04

+0

你的意思是XML結果? – Lucifer 2012-04-03 02:49:32

0

使用下面的代碼來發送郵件

Intent sharingIntent = new Intent(Intent.ACTION_SEND); 
sharingIntent.setType("vnd.android.cursor.dir/email"); 
String to[] = "[email protected]"; 
sharingIntent.putExtra(Intent.EXTRA_EMAIL, to); 
sharingIntent.putExtra(Intent.EXTRA_STREAM,filePath); 
sharingIntent.putExtra(Intent.EXTRA_SUBJECT,"subject"); 
startActivity(Intent.createChooser(sharingIntent, "Send email")); 
+0

感謝Agarawl。嘗試了你的建議,但仍然選擇GMail,Skype和Google Docs。 (必須稍微改變它才能工作,將「{}」添加到文字和製作的filePath文件URI中)。 – user1139880 2012-04-03 02:45:12

+0

實際上你需要什麼 – 2012-04-03 03:01:41

相關問題