电子邮件中附加的图片未收到 [英] Image attached in email is not received

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

问题描述

我正在尝试以编程方式将图像附加到我的应用程序的电子邮件正文中。我看到一些关于如何做到这一点的主题,并将我的代码完全一样,但是没有使用图像另一方(从这个帖子)。
更多信息是我的代码:

i am trying to programmatically attach an image to an email body from my app .I've seen some topics about how to do that and put my code exactly the same way but it's useless i don't get the image in the other side (from this post ) . for more information here is my code:

Intent emailIntent=new Intent(Intent.ACTION_SEND);
            emailIntent.setData(Uri.parse("mailto:"));
            emailIntent.setType("image/jpg");
            emailIntent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.mail_partage_objet));
            emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(readEmailTemplate()));
            String imageFilePath=Constants.PHOTO_CACHE_PATH+"/"+currentPlace.getPhotoFileName();
            Log.d(TAG,"Picture Path: "+imageFilePath);
            emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(imageFilePath));
            startActivity(Intent.createChooser(emailIntent, getResources().getString(R.string.email_share)));

其中PHOTO_CACHE_PATH是保存图像的目录的路径,它位于SDcard上

where PHOTO_CACHE_PATH is the path of directory where the image is saved and it's on SDcard

推荐答案

我想你忘了: emailIntent.setType(application / octet-stream);

multiattachments的示例:

Example for multiattachments:

    Intent exportMessageIntent = new Intent(
            android.content.Intent.ACTION_SEND_MULTIPLE);
    exportMessageIntent.setType("text/plain");
    exportMessageIntent.setType("application/octet-stream");
    ArrayList<Uri> uris = new ArrayList<Uri>();

            //array of urls to your files on device - they are strings
    filePaths = new String[] { "path1","path2" };  //for your case just insert imageFilePath -> filePaths = new String[] { imageFilePath };
            //create files from string array of paths
    for (String file : filePaths) {
        File fileIn = new File(file);
        Uri u = Uri.fromFile(fileIn);
        uris.add(u);
    }
    exportMessageIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,
            uris);

    exportMessageIntent
            .putExtra(Intent.ACTION_DEFAULT, "test/");

    exportMessageIntent.putExtra(Intent.EXTRA_SUBJECT,"Subject text");

    exportMessageIntent.putExtra(Intent.EXTRA_TEXT,"bodytext");

    startActivity(exportMessageIntent);

希望它有帮助,
Toni

Hope it helps, Toni

这篇关于电子邮件中附加的图片未收到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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