gpt4 book ai didi

安卓 Intent : Send an email with attachment

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:18:31 25 4
gpt4 key购买 nike

我想通过电子邮件发送多个文件。我找到了这个 Android multiple email attachments using Intent但它确实有效,而且我没有收到任何错误消息。它只是不附加文件(我也尝试只发送一个文件,但我得到了相同的结果)。

我是不是监督了什么?你有什么建议吗?

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);
}

日志:

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

最佳答案

这段代码对我有用。 pdfFiles 的类型为 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)));

关于安卓 Intent : Send an email with attachment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9587559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com