Search code examples
androidwebviewandroid-webviewandroid-2.3-gingerbread

Web Page not available on Gingerbread


If I run my code on Gingerbread Emulator it gives me:

Web Page not available and the source code of the page listed below.

If I run the app on ICS or JB (both phisical phone and emulator) it does work:

    webview = new WebView(InterfacciaPrincipale.this);

    webview.getSettings().setBuiltInZoomControls(true);
    webview.loadData(Html.getHtml(), "text/html", "UTF-8");
    webview.getSettings().setJavaScriptEnabled(true);
    webview.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            new M("Caricamento", getApplicationContext());
            Log.v("ESSE3", "shouldOverrideUrlLoading()");
            System.out.println(url);
            try {
                Html.setHtml(Connessione.generaStringaHTML(Connessione.getUrl(url)));
            } catch (IOException e) {
                e.printStackTrace();
            }
            System.out.println(Html.getHtml());
            webview.loadDataWithBaseURL(null,Html.getHtml(), "text/html", "UTF-8",null);
            return true;

        }
    });

Yes, the INTERNET permission is there (it works on ICS and JB...).


Solution

  • Instead of:

    webview.loadData(Html.getHtml(), "text/html", "UTF-8");
    

    use

    webview.loadDataWithBaseURL(null,Html.getHtml(), "text/html", "UTF-8",null);
    

    on Gingerbread. This fixed my problem.