Android电子邮件与存储中的图像

时间:2014-02-12 07:33:26

标签: android email html-email email-attachments

我有一个应用程序,我需要发送带有文本和img的电子邮件.... img是从这样的SD卡来的

enter image description here 我做到了......

emailIntent.setData(Uri.parse("mailto:"));
          emailIntent.setType("text/plain");
          emailIntent.setType("application/image");

          emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
          emailIntent.putExtra(Intent.EXTRA_CC, CC);
          emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject");
          emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message goes here");
          Spanned spanned_str_Caution = Html.fromHtml(str_Caution);
          String text=tv_viewinfo.getText()+""+spanned_str_Caution;
          emailIntent.putExtra(Intent.EXTRA_TEXT, text);




            //  emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/saved_images/test.PNG"));
            //  emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/saved_images/test.PNG"));
             // root
              //emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/saved_images/test.PNG"));
            //  emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/saved_images/test.PNG"));
             startActivity(Intent.createChooser(emailIntent, "Send mail..."));
             finish();
             Log.i("Finished sending email...", "");

但这不适合我和应用程序崩溃..

2 个答案:

答案 0 :(得分:0)

你可以这样试试,

Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
        // intent.setType("text/plain");

        intent.setType("message/rfc822");
        // intent.setType("image/*");
        intent.putExtra(Intent.EXTRA_SUBJECT, "Img Send");
        intent.putExtra(Intent.EXTRA_TEXT, "test");
        ArrayList<Uri> uris = new ArrayList<Uri>();

        for (int k = 0; k < fmsgList.size(); k++) {
            File fileIn = new File(fmsgList.get(k));
            Uri u = Uri.fromFile(fileIn);
            uris.add(u);
        }
        File root = Environment.getExternalStorageDirectory();

        File file1 = new File(root, "/File.txt");
        Uri u = Uri.fromFile(file1);
        uris.add(u);

        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        // startActivity(intent);
        startActivity(Intent.createChooser(intent, "Send E-mail..."));

答案 1 :(得分:0)

像这样发送路径

String file_path = Environment.getExternalStorageDirectory() +  "/saved_images/test.PNG"
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(file_path);