【发布时间】:2015-12-23 10:06:37
【问题描述】:
我们想在 webview 中离线(没有互联网连接)显示 html 页面及其内容,如文本、图像等。我们只能显示文本。对于图像,我们将图像从图像 url 存储在内部存储(sd 卡)上,并将该图像 url(服务器 url)替换为图像内部存储(sd 卡)路径。
但是,这些图像没有显示在 webview 中。
例如, 下面是html中的img标签..
<img alt="img" class="center_top_img" src="http://test.com/uploads/section/images/523.jpg" />
我们将上面的图片url(服务器url)替换为图片内部存储(sd卡)路径
<img alt="img" class="center_top_img" src=\"file:///data/data/com.app.test/files/523.jpg\" />
【问题讨论】:
-
您检查替换路径是否有效?即文件存在于同一路径上或不存在一次检查。如果有效,则使用基本 URL 加载数据:==> webView.loadDataWithBaseURL("", html, "text/html","utf-8", ""); stackoverflow.com/a/5055471/2983864
-
是.. 路径有效。文件存在那里。我们已经替换了这样的网址 并且还使用了 webView.loadDataWithBaseURL("", html, "text/html","utf-8", "");但它不起作用..
-
你能分享你的代码吗?
-
使用 Environment.getExternalStorageDirectory() 路径,图像显示在 webview 但使用 getFilesDir() 时,图像存储在 data/data/com.yourapp/files/ 路径中但不显示..让我知道我们是否做错了什么。
标签: android html image webview offlineapps