我会尽力解释我的问题。
我想要做的是创建一个带有HTML字符串的文件。此HTML字符串包含至少一个图像URL。我想将此文件附加到电子邮件意图。
电子邮件意图成功获取附件,但是当我查看它时,图像被破坏,与图像相关联的链接(即图像应该是可点击的)不起作用。
以下是我所拥有的:
HTML文件htmlString
:
<html>
...
<body>
...
<tr style="background-color:#000000;">
<td colspan="2" align="center" >
<a href="www.google.com">
<img src="http://full_path_to_image.png"/></a></td>
</tr>
...
</body>
</html>
http://full_path_to_image.png
将替换为实际的图片网址。
从字符串创建html文件:
String fileName = "fileName.html";
File theFile = null;
try {
theFile = new File(getActivity().getExternalCacheDir(), fileName);
stringToFile(htmlString,theFile.getAbsoluteFile());
} catch (IOException e) {
Toast.makeText(getActivity().getApplicationContext(), "Error creating temporary file!", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
附加电子邮件:
ArrayList<Uri> filesToAttach = new ArrayList<Uri>();
filesToAttach.add(Uri.fromFile(theFile));
然后我设置了意图,附加文件,一切正常。但是,如果我打开附件,图像似乎会被破坏。如果我点击损坏的图像,我会在浏览器上显示一个页面,并显示错误消息:
The webpage at content://com.android.htmlfileprovider/storage/emulated/0/Android/data/com.test.testApplication/cache/www.google.com could not be loaded because:
net::ERR_UNKNOWN_URL_SCHEME
我不确定如何让我的图像工作以及如何让链接正常运行。