Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebView works on android 2.3.3, shows blank page on 4.0.1

I don't think this is a duplicate, but this question may be relevant.

As of title: this works perfectly on android 2.3.3, randomly shows a blank page on 4.0.1. It usually works at first, then start displaying blank pages until the application is reinstalled.

The code I'm using to display a simple (html only) webpage is a follows:

@Override
public void afterTextChanged(final Editable arg0){
    final String result = getResult();
    final String base64 = encode(result);
    //This is the WebView
    results.loadData(base64, "text/html; charset=utf-8", "base64");
}

private String encode(final String value){
    try{
        final byte[] bytes = value.getBytes("UTF-8");
        final String base64 = Base64.encodeToString(bytes,
                              android.util.Base64.DEFAULT);
        return base64;
    }
    catch(UnsupportedEncodingException e){
        return "YOULOOZE";
    }
}
like image 834
miniBill Avatar asked Dec 29 '25 03:12

miniBill


2 Answers

Check that your HTML is well formatted. I am not sure of the Doctype it validates against.

This happened to me because I used

<script ... />

instead of

<script ...></script>

Any tiny error will make your webview fail silently.

like image 155
Maragues Avatar answered Dec 31 '25 19:12

Maragues


I'm not sure that is your solution but can help. Since Android 4.0 WebKit updated into version 534.30. I noticed that on some web pages, after it has completed loading, the WebView redirects its content to a new page that says the following: "Webpage not available The webpage at file:///android_asset/webkit/ might be temporarily down or it may have moved permanently to a new web address". This is bug of new version of WebKit, in my case javascript from assets folder don't work in offline.

like image 39
Artyom Kiriliyk Avatar answered Dec 31 '25 17:12

Artyom Kiriliyk