Skip to content Skip to sidebar Skip to footer

Android Webview Showing Blank Page For Local Files

My android WebView is showing a blank page when I try to load 'file:///android_asset/index.html' and it perfectly loads other url like 'http://twitter.com'. My activity public cla

Solution 1:

get string content from your assests file using below code

publicstatic String getStringFromAssets(String name, Context p_context)
    {
        try
        {
            InputStream is = p_context.getAssets().open(name);
            int size = is.available();
            byte[] buffer = newbyte[size];
            is.read(buffer);
            is.close();
            String bufferString = new String(buffer);
            return bufferString;
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        returnnull;

    }

and load content using below code

Stringm_data= getStringFromAssets("index.html", this);
webView.loadDataWithBaseURL("file:///android_asset/", m_data, "text/html", "utf-8", null);

Hope it works for you !!

Solution 2:

Checkout if there are any errors in javascript code associated with the html page. If so android studio doesn't point out errors in js file.

I fixed the errors in the js file and it worked.

Post a Comment for "Android Webview Showing Blank Page For Local Files"