由网友(習慣ㄋ孤單)分享简介:我要发通过电子邮件发送多个文件。我找到了这个Android使用意向多个电子邮件附件,但它的工作,我没有得到任何错误消息。它只是不附加文件(我也尝试发送只有一个文件,但我得到了同样的结果)。 难道我还监督什么?你有什么建议吗? 私有静态无效的电子邮件(上下文的背景下,字符串emailTo,字符串emailCC, 主...
我要发通过电子邮件发送多个文件。我找到了这个Android使用意向多个电子邮件附件,但它的工作,我没有得到任何错误消息。它只是不附加文件(我也尝试发送只有一个文件,但我得到了同样的结果)。
难道我还监督什么?你有什么建议吗?
私有静态无效的电子邮件(上下文的背景下,字符串emailTo,字符串emailCC, 主题字符串,字符串emailText,列表与LT;弦乐>文件路径){ //需要发送多个来获得多个附件 最终意图emailIntent =新意图(android.content.Intent.ACTION_SEND_MULTIPLE); emailIntent.setType(文/ XML); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, 新的String [] {emailTo}); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,学科); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,emailText); //必须是一个ArrayList ArrayList的<&乌里GT;的URI =新的ArrayList<&乌里GT;(); //从路径转换到Android友好Parcelable的URI 对于(字符串的文件:文件路径) { 文件FILEIN =新的文件(文件); //乌里U = Uri.fromFile(FILEIN); 乌里U = Uri.fromFile(新文件(Environment.getExternalStorageDirectory(),blabla.xml)); Log.v(BLA,文件路径:+ u.toString()); uris.add(U); 乌里B = Uri.fromFile(新文件(Environment.getExternalStorageDirectory(),blabla.es)); uris.add(二); Log.v(BLA,文件路径:+ b.toString()); } emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,URI的); context.startActivity(emailIntent);}
LogCat中:
16 03-06:08:50.940:信息/ ActivityManager(69):开始:意向{行动= android.intent.action.SEND_MULTIPLE典型值=文本/ XML CMP =融为一体。 android.email/.activity.MessageCompose(有临时演员)}从PID 43603-06 16:08:52.130:信息/ ActivityManager(69):显示com.android.email/.activity.MessageCompose:+ 1s118ms03-06 16:08:52.470:WARN / IInputConnectionWrapper(436):上的非活动InputConnection showStatusIcon
解决方案
这code为我工作。 pdfFiles的类型为的ArrayList<开放的方式>
意图shareIntent =新意图(android.content.Intent.ACTION_SEND_MULTIPLE); shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,它是gettext(R.string.share_subject)); CharSequence的序列= Html.fromHtml(mOCRText.toString()); shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,SEQ); shareIntent.setType(应用程序/ PDF格式); shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,pdfFiles); startActivity(Intent.createChooser(shareIntent,它是gettext(R.string.share_chooser_title)));
I want to send send several files via eMail. I found this Android multiple email attachments using Intent but it does work and I don't get any error message. It just don't attach the files (I also tried to send just one file but I got the same result).
Did I have overseen something.? Do you have any suggestions?
private static void email (Context context, String emailTo, String emailCC,
String subject, String emailText, List<String> filePaths)
{
//need to "send multiple" to get more than one attachment
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("text/xml");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[]{emailTo});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailText);
//has to be an ArrayList
ArrayList<Uri> uris = new ArrayList<Uri>();
//convert from paths to Android friendly Parcelable Uri's
for (String file : filePaths)
{
File fileIn = new File(file);
// Uri u = Uri.fromFile(fileIn);
Uri u = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "blabla.xml"));
Log.v("bla", "filepath: " +u.toString());
uris.add(u);
Uri b = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "blabla.es"));
uris.add(b);
Log.v("bla", "filepath: " +b.toString());
}
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
context.startActivity(emailIntent);
}
LogCat:
03-06 16:08:50.940: INFO/ActivityManager(69): Starting: Intent { act=android.intent.action.SEND_MULTIPLE typ=text/xml cmp=com.android.email/.activity.MessageCompose (has extras) } from pid 436
03-06 16:08:52.130: INFO/ActivityManager(69): Displayed com.android.email/.activity.MessageCompose: +1s118ms
03-06 16:08:52.470: WARN/IInputConnectionWrapper(436): showStatusIcon on inactive InputConnection
解决方案
This code is working for me. pdfFiles is of type ArrayList<Uri>
.
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getText(R.string.share_subject));
CharSequence seq = Html.fromHtml(mOCRText.toString());
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, seq);
shareIntent.setType("application/pdf");
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, pdfFiles);
startActivity(Intent.createChooser(shareIntent, getText(R.string.share_chooser_title)));
相关推荐
最新文章