如何显示在电子邮件正文中的图像?文中、图像、电子邮件

2023-09-12 06:19:33 作者:无限嚣张

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

我要显示的图像在电子邮件正文中,

我曾试图HTML图像标记&LT; IMG SRC = \HTTP://url/to/the/image.jpg \&gt;中和我得到的输出,你可以在如何在电子邮件正文中添加图片。< /一>,所以我累了 Html.ImageGetter

它不工作对我来说,这也给了我同样的输出,所以我有一个疑问,是有可能做到这一点,

我的code

 意向书我=新的意图(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_EMAIL,新的String [] {abc@gmail.com});
i.putExtra(Intent.EXTRA_TEXT,
    Html.fromHtml(嗨&LT; IMG SRC =HTTP://url/to/the/image.jpg'>
    imgGetter,
    空值));

i.setType(图像/ PNG);
startActivity(Intent.createChooser(我,电子邮件:));


私人ImageGetter imgGetter =新ImageGetter(){

    公众可绘制getDrawable(字符串源){
        可绘制绘制= NULL;
            尝试 {
                绘制= getResources()getDrawable(R.drawable.icon)。
                drawable.setBounds(0,0,drawable.getIntrinsicWidth(),
                    drawable.getIntrinsicHeight());
            }赶上(例外五){
                e.printStackTrace();
                Log.d(抛出异常,e.getMessage());
            }
            返回绘制;
    }
};
 

更新1:如果我使用 ImageGetter $ C $下的TextView 我能够得到的文字和图片,但我无法看到图像中的电子邮件正文

下面是我的code:

  TextView的T = NULL;
T =(TextView中)findViewById(R.id.textviewdemo);
t.se​​tText(Html.fromHtml(嗨&LT; IMG SRC =HTTP://url/to/the/image.jpg'>
    imgGetter,
    空值));
 
怎么在邮件正文中添加图片

更新2:我用了大胆的标记,锚标记,如图一所示,这些标签都工作正常,但是当我使用img标签,我可以看到一个方框它说的OBJ

  i.putExtra(Intent.EXTRA_TEXT,Html.fromHtml(&LT; B&GT;喜&LT; / B&GT;&LT; A HREF =HTTP://www.google.com/ '&GT;连结&所述; / a取代;&所述; IMG SRC ='的http://url/to/the/image.jpg'>,
        imgGetter,
        空值));
 

解决方案

不幸的是,它不可能与意图做到这一点。

为什么例如粗体文字显示在EditText上,而不是一个图片是的ImageSpan 的没有。因此,当Intent.EXTRA_TEXT检索在新的活动的ImageSpan将无法unparcel并为此不追加到的EditText样式的一部分。

使用其他方法,你不传递数据的意图是不幸的是没有可能在这里,你是不是在接收活动的控制。

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

I want to show an image in the email body,

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 add 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,

My code

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

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

Here is my code:

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

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

解决方案

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

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.