Android 如何将html从资产文件夹加载到webview
我将html页面存储在资产文件夹中,并将其插入sqlite。 我将html页面作为文本存储在sqlite中 有人知道如何将我的html页面加载到webview吗 我试图添加一些代码,但没有工作Android 如何将html从资产文件夹加载到webview,android,html,sqlite,webview,Android,Html,Sqlite,Webview,我将html页面存储在资产文件夹中,并将其插入sqlite。 我将html页面作为文本存储在sqlite中 有人知道如何将我的html页面加载到webview吗 我试图添加一些代码,但没有工作 if (info.size() != 0) { lu.setText(info.get(2)); WebView wb = (WebView) findViewById(R.id.mywebview); wb.loadDataWithBaseURL(
if (info.size() != 0) {
lu.setText(info.get(2));
WebView wb = (WebView) findViewById(R.id.mywebview);
wb.loadDataWithBaseURL("file:///android_asset/"+lu,"text/html","UTF-8",null);
}
你的问题已经有了详细的答案,所以。。。我相信其中一个答案应该能解决你的问题。。。希望这有助于gudluck。什么是lu?它应该是逗号而不是+ 在任何情况下,方法
loadDataWithBaseURL
都有5个参数:
base,data,mimetype,encoding,historyUrl
例如:
readAssetFileAsString如下所示:
private String readAssetFileAsString(String sourceHtmlLocation)
{
InputStream is;
try
{
is = getContext().getAssets().open(sourceHtmlLocation);
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
return new String(buffer, "UTF-8");
}
catch(IOException e)
{
e.printStackTrace();
}
return "";
}
嘿,El_Auls,你应该让你的问题更清楚。。。通过提供更多详细信息,说明您如何尝试将其加载到您的webview并失败。我已经添加了我的代码,请帮助我T,T
private String readAssetFileAsString(String sourceHtmlLocation)
{
InputStream is;
try
{
is = getContext().getAssets().open(sourceHtmlLocation);
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
return new String(buffer, "UTF-8");
}
catch(IOException e)
{
e.printStackTrace();
}
return "";
}