如何将附件添加到电子邮件?
我有这封电子邮件发送代码,不显示选择器(好)。如何扩展它以包含文件附件,而不涉及选择器?如何将附件添加到电子邮件?
// 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);
试试这个:
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);
尝试下面的代码,
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);
感谢路西法。试过它,但得到了与Picasa,消息等长选择器 – user1139880 2012-04-03 02:49:04
你的意思是XML结果? – Lucifer 2012-04-03 02:49:32
使用下面的代码来发送邮件
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"));
感谢Agarawl。尝试了你的建议,但仍然选择GMail,Skype和Google Docs。 (必须稍微改变它才能工作,将“{}”添加到文字和制作的filePath文件URI中)。 – user1139880 2012-04-03 02:45:12
实际上你需要什么 – 2012-04-03 03:01:41
谢谢伊姆兰。试了一下,但得到了一个有几个选项的选择器。我的问题是如何添加附件而不添加选择器。 – user1139880 2012-04-03 02:50:39