如何在电子邮件正文中显示图像? [英] How to show an image in the email body?

查看:189
本文介绍了如何在电子邮件正文中显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:我不想将图像附加到电子邮件

Note: I don't want to attach the Image to the Email

我想显示电子邮件正文中的图像

I want to show an image in the email body,

我已尝试过HTML图像标签< img src = \http:// url / to /the/image.jpg\\">,我得到的输出,你可以看到在我的问题在如何在电子邮件正文中添加图像,所以我累了 Html.ImageGetter

I had tried the HTML image tag <img src=\"http://url/to/the/image.jpg\">" and I got output as you can see in this my question on How to add an image in email body, so I tired Html.ImageGetter.

它对我来说不起作用,它也给我相同的输出,所以我有疑问是否可以这样做,

It does not work for me, it also gives me the same output, so I have a doubt is it possible to do this,

我的代码

Intent i = new Intent(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_EMAIL,new String[] {"abc@gmail.com"}); 
i.putExtra(Intent.EXTRA_TEXT,
    Html.fromHtml("Hi <img src='http://url/to/the/image.jpg'>",
    imgGetter,
    null));

i.setType("image/png");
startActivity(Intent.createChooser(i,"Email:"));


private ImageGetter imgGetter = new ImageGetter() {

    public Drawable getDrawable(String source) {
        Drawable drawable = null;
            try {
                drawable = getResources().getDrawable(R.drawable.icon);
                drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
                    drawable.getIntrinsicHeight());
            } catch (Exception e) {
                e.printStackTrace();
                Log.d("Exception thrown",e.getMessage());
            } 
            return drawable;
    }
};

更新1:如果我使用 ImageGetter 代码 TextView 我可以获取文字和图像,但我无法在电子邮件正文中看到图像

UPDATE 1: If I use the ImageGetter code for TextView I am able to get the text and image but I am not able to see the image in the email body

这是我的代码:

TextView t = null;
t = (TextView)findViewById(R.id.textviewdemo);
t.setText(Html.fromHtml("Hi <img src='http://url/to/the/image.jpg'>",
    imgGetter,
    null));

更新2:我使用了粗体标签和锚标签在这些标签下面工作正常,但是当我使用img标签时,我可以看到一个方框,说为OBJ

UPDATE 2: I had used bold tag and anchor tag as i shown below these tag are working fine , but when i used img tag i can able to see a square box which say as OBJ

 i.putExtra(Intent.EXTRA_TEXT,Html.fromHtml("<b>Hi</b><a href='http://www.google.com/'>Link</a> <img src='http://url/to/the/image.jpg'>",
        imgGetter,
        null));


推荐答案

不幸的是,不可能用Intents做到这一点。

Unfortunately, it's not possible to do this with Intents.

例如 bold 文本的原因显示在EditText中,而不是图片的原因是 StyleSplan 正在实现 Parcelable ,而 ImageSpan 没有。所以当在新的Activity中检索到Intent.EXTRA_TEXT时,ImageSpan将无法解开,因此不会成为EditText附加的样式的一部分。

The reason why for example bold text is displayed in the EditText and not an Image is that StyleSplan is implementing Parcelable whereas ImageSpan does not. So when the Intent.EXTRA_TEXT is retrieved in the new Activity the ImageSpan will fail to unparcel and therefor not be part of the style appended to the EditText.

使用其他方法您不会通过意图传递数据,不幸的是,由于您无法控制接收活动,因此不可能。

Using other methods where you don't pass the data with the Intent is unfortunately not possible here as you're not in control of the receiving Activity.

这篇关于如何在电子邮件正文中显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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