我正在尝试加载一个存储在数据库中的html字符串,其中包含一个图像到一个WebView
中。图像存储在内部存储器中。我给出了一个html string.But的参考,它不工作。有帮助吗?
String content="<p>Can we have a rotational" +
" symmetry of order more than 1 whose angle of rotation is </p>\n" +
"\n <p>(i) <img alt=\"45\\degree\" src=\"file:///storage/emulated/01484890695248.jpg\" /></p>\n" +
"\n<p>(ii) <img alt=\"35\\degree\" src=\"file:///storage/emulated/01484890697301.jpg\" /></p>";
WebView00.loadDataWithBaseURL("", content, "text/html","UTF-8", "");
WebView00.getSettings();
发布于 2017-02-16 14:20:59
试着这样做
String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
String imagePath = "file://"+ base + "/image_name.jpg";
String html = "<html><head></head><body> <img src=\""+ imagePath + "\"> </body></html>";
webView.loadDataWithBaseURL("", html, "text/html","utf-8", "");
发布于 2017-02-16 14:19:38
将图像放入您的assets
文件夹中。然后使用相应的前缀
file:///android_asset/
发布于 2017-02-16 14:46:17
问题出在文件路径中
file:///storage/emulated/01484890695248.jpg
将会是
file:///storage/emulated/0/01484890695248.jpg
感谢@Charuක的帮助..
https://stackoverflow.com/questions/42266264
复制相似问题