Webview shouldOverrideUrlLoading works in previous android versions except 4.1.x jellybean
Asked Answered
C

1

8

the following code works fine in all devices running android 2.x , but not in a Nexus 7 tablet with 4.1.2

The problem is that the shouldOverrideUrlLoading never run. The onPageFinished run ok

I'll appreciate any available help.

wv = (WebView) root_view.findViewById(R.id.wv);
wv.setBackgroundColor(res.getColor(R.color.def_bgr_color));
wv.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
wv.setWebViewClient(new MyWebViewClient() );

WebSettings web_settings = wv.getSettings();
web_settings.setJavaScriptEnabled(true);
web_settings.setLoadWithOverviewMode(true);
web_settings.setUseWideViewPort(false);
web_settings.setPluginsEnabled(true);
web_settings.setSupportZoom(true);
web_settings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);

public class MyWebViewClient extends WebViewClient {
    public MyWebViewClient() {
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        Log.i(TAG, "RUN shouldOverrideUrlLoading" );
        return true;

    }

    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        Log.i(TAG, "RUN onPageFinished" );
    }
}


String html_str = ... something html ...

wv.loadDataWithBaseURL("file:///android_asset/", html_str, "text/html", "utf-8", null);
Cowell answered 8/11, 2012 at 15:6 Comment(0)
S
0

Did you try loading the html_str as a html file on normal desktop chrome browser? If not try it, it may lead you somewhere.

In earlier version of android cross domain scripting was allowed but for security reasons in the latest version of android, webkit based webview prevents cross domain scripting. This may be preventing your page from loading [Taking a wild guess here!].

Skvorak answered 24/1, 2013 at 6:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.