Android意图:发送带有附件的电子邮件 [英] Android Intent: Send an email with attachment

查看:269
本文介绍了Android意图:发送带有附件的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过电子邮件发送几个文件。我发现这个
使用意图的Android多个电子邮件附件,但它确实工作,我没有收到任何错误信息。它只是不附加文件(我也试图发送只有一个文件,但我得到相同的结果)。



我有监督的东西吗?你有什么建议吗?

  private static void email(Context context,String emailTo,String emailCC,
String subject ,String emailText,List< String> filePaths)
{
//需要发送多个以获取多个附件
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);
//必须是一个ArrayList
ArrayList< Uri> uris = new ArrayList< Uri>();
//从路径转换为Android友好的可扩展Uri的
(String file:filePaths)
{
文件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):启动: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):显示com.android.email/.activity.MessageCompose:+ 1s118ms
03-06 16:08:52.470:WARN / IInputConnectionWrapper(436):showStatusIcon处于非活动状态InputConnection


解决方案

这段代码正在为我工​​作。 pdfFiles类型为 ArrayList< Uri>

  Intent shareIntent = new意图(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)));


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

这篇关于Android意图:发送带有附件的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆