所以,我有这个toHtml函数:
public String toHtml() {
Uri imageUri = Uri.fromFile(new File("android_asset/" + getFullAssetsFilepath()));
String html = getString(R.string.email_image, imageUri);
html += getString(R.string.email_caption, caption);
return html;
}
<string name="email_image"><p><img src=\"%1$s\" /></string>
<string name="email_caption"><br/>%1$s</p></string>
这是生成的内容:
<p><img src="file:///android_asset/images/00001.jpg" /><br/>Bird</p>
还有其他函数的其他htmls,它们一起传递给这个sendEmail函数:
private void sendEmail(String subject, String content) {
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_TEXT,
Html.fromHtml(content + mContext.getString(R.string.email_generated_by_vancouver_trees)));
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.setType("text/html");
mContext.startActivity(Intent.createChooser(email, getString(R.string.share)));
}
电子邮件代理知道它是一张图片,但我在电子邮件中收到的是: [OBJ] 鸟
还有另一种方法来为资产生成src吗?我在看Embedding image in email in Android。
我也试过这个
XML
<string name="email_image"><p><img src=\"data:image/png;base64,%1$s\" /></string>
<string name="email_caption"><br/>%1$s</p></string>
java
public String toHtml(Context context) {
try {
InputStream istr = context.getAssets().open(getFullAssetsFilepath());
Bitmap bitmap = BitmapFactory.decodeStream(istr);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream .toByteArray();
String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
String html = context.getString(R.string.email_image, encoded);
html += context.getString(R.string.email_caption, caption);
return html;
} catch (IOException e) {
}
return "";
}
但我仍然以[obj]框
结束事实上,我已经尝试过src =&#34; [静态图像html]&#34;我仍然得到[obj]