android - Android WebView加载本 map 片的方法

标签 android image webview

我正在尝试将存储在数据库中的包含图像的 html 字符串加载到 WebView 中。图像存储在内部存储器中。我正在提供对 html 字符串的引用。但它不起作用。有帮助吗?

String content="<p>Can we have a rotational" +
    " symmetry of order more than 1 whose angle of rotation is&nbsp;</p>\n" +
    "\n <p>(i)&nbsp;<img alt=\"45\\degree\" src=\"file:///storage/emulated/01484890695248.jpg\" /></p>\n" +
    "\n<p>(ii)&nbsp;<img alt=\"35\\degree\" src=\"file:///storage/emulated/01484890697301.jpg\" /></p>";

WebView00.loadDataWithBaseURL("", content, "text/html","UTF-8", "");
WebView00.getSettings();

最佳答案

这样试试

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

关于android - Android WebView加载本 map 片的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42266264/

相关文章:

android - Animation.setFillAfter/Before - 它们是否工作/它们是做什么用的?

java - 无法创建抽象类 Random kotlin 的实例

java - 没有找到适合 add() 错误的方法

css - 为什么我不能在 IE7 中单击带有嵌套图像的链接?

javascript - 使用 Electron 在 Web View 中实现缩放功能

android - 在onReceivedError屏幕上显示自定义

java - Intellij Idea不显示源代码文件

ios - 在ios应用程序上缓存图像的最佳方式?

c# - 我怎样才能返回图像?

java - 网页 View 崩溃