-1

I store my html page in asset folder and insert it to my sqlite. i store my html page as text in sqlite.

Anyone know how to load my html page into webview?

i've tried to add some code, and not working

    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);
    }
El_Auls
  • 11
  • 3

2 Answers2

0

You question already has well elaborated answers here on SO Webview load html from assets directory... I believe one of the answers should solve your problem... Hope that helps gudluck.

Community
  • 1
  • 1
Fenn-CS
  • 863
  • 1
  • 13
  • 30
0

what is lu?, should it be a comma instead of +?

In any case, the method loadDataWithBaseURL takes 5 arguments:

base, data, mimetype, encoding, historyUrl

E.g:

wbHelp.loadDataWithBaseURL("file:///android_asset/", 
readAssetFileAsString("index.html"), 
"text/html", 
"UTF-8", 
null);

readAssetFileAsString is as follows:

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 "";
}
behelit
  • 1,765
  • 2
  • 20
  • 34
  • Shouldn't the `is.close()` statement be placed inside a `finally` block? (initialising `is` to `null` before the `try` block) – Aldan Creo Dec 19 '21 at 20:11