Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android-将HTML从数据库加载到WebView_Android_Html_Webview_Local Storage - Fatal编程技术网

android-将HTML从数据库加载到WebView

android-将HTML从数据库加载到WebView,android,html,webview,local-storage,Android,Html,Webview,Local Storage,因此,我试图将一些HTML从sqlite数据库加载到webview中。 这非常好,因为html呈现得非常漂亮,但问题来了。未加载html中添加的本地文件。我将它添加到这个层次结构中的assets文件夹:assets/folder1/folder2/placeholder.png,但是我得到了一个不允许加载本地资源的错误消息:error。请问我怎样才能通过这个 请注意,数据是从数据库填充的 webView = (WebView) findViewById(R.id.webView); we

因此,我试图将一些HTML从sqlite数据库加载到webview中。 这非常好,因为html呈现得非常漂亮,但问题来了。未加载html中添加的本地文件。我将它添加到这个层次结构中的assets文件夹:assets/folder1/folder2/placeholder.png,但是我得到了一个不允许加载本地资源的错误消息:error。请问我怎样才能通过这个

请注意,数据是从数据库填充的

webView = (WebView) findViewById(R.id.webView);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setAllowFileAccess(true);
    webView.loadData(data, "text/html", "UTF-8");
这是上面web视图的代码

<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><h2 style="color:red;">Hello  Chief</h2><p>This is just a demo HTML content rendered beautifully</p><br><img src="file:///android_asset/folder1/folder2/placeholder.png"></body></html>

谢谢

在webview中有一种方法可以用基本url加载html文件

webview.loadDataWithBaseURL(String baseUrl, String data, String mimeType, String encoding, String historyUrl)
在baseUrl中,将其作为

file:///android_asset/

或者使用Jsoup解析器解析html文档,并使用Jsoup解析器替换所需标记的src。

感谢您的帮助,但现在我无法打开资产URL:file:///android_asset/folder1/folder2/placeholder.png. 我是否删除了我的中的(文件),因为它现在是基本url并相对链接到它?比如,请看看你是如何做到的?(将html从sqlite加载到web视图)。你能分享一些代码吗?哦,哇,那就像差不多一年前的@Mwas,所有的代码都丢失在某个地方了。但它只是将html保存到sqlite数据库并输出它。真的没什么不寻常的
file:///android_asset/