San*_*esh 23 java email android image inline-images
注意:我不想将图像附加到电子邮件中
我想在电子邮件正文中显示图片,
我已经尝试了HTML图像标记<img src=\"http://url/to/the/image.jpg\">"
,我得到了输出,你可以在我的问题中看到如何在电子邮件正文中添加图像,所以我累了Html.ImageGetter
.
它对我不起作用,它也给了我相同的输出,所以我怀疑是否可以这样做,
我的代码
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;
}
};
Run Code Online (Sandbox Code Playgroud)
更新1:如果我使用ImageGetter
代码TextView
我能够获取文本和图像,但我无法在电子邮件正文中看到图像
这是我的代码:
TextView t = null;
t = (TextView)findViewById(R.id.textviewdemo);
t.setText(Html.fromHtml("Hi <img src='http://url/to/the/image.jpg'>",
imgGetter,
null));
Run Code Online (Sandbox Code Playgroud)
更新2:我使用了粗体标签和锚标签,因为我在下面显示这些标签工作正常,但是当我使用img标签时,我能够看到一个方形框,表示为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));
Run Code Online (Sandbox Code Playgroud)
roc*_*dev 15
不幸的是,使用Intents不可能做到这一点.
为什么例如之所以大胆的文字显示在EditText上,而不是一个图像是StyleSplan正在实施Parcelable而ImageSpan没有.因此,当在新的Activity中检索到Intent.EXTRA_TEXT时,ImageSpan将无法取消选中,因此不会成为附加到EditText的样式的一部分.
遗憾的是,使用其他方法不使用Intent传递数据是不可能的,因为您无法控制接收活动.
归档时间: |
|
查看次数: |
13509 次 |
最近记录: |