2

I have some web page which open in WebView.

<body onload="window.location.href='htcmd:loaded';"> 

After load we open back url "htcmd:loaded" and intercept in code. Like this:

getWebView().getSettings().setJavaScriptEnabled(true);
        getWebView().setWebViewClient(new WebViewClient() {
            @Override
            public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
                handler.proceed();
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                if ("htcmd:loaded".equals(url)) {
                    Toast.makeText(getActivity(), "htcmd:loaded", Toast.LENGTH_SHORT).show();
                }
                return true;
            }
        });
        getWebView().loadUrl("https://some.url");

On android 4.4.2 in first start all is well. But if I kill app and open after first run, web page not render. But if I tap on screen or change orientation web page appears. Where is problem?

SOLUTION: I have two hacks))) First: add a java script to web page:

<body onload="setTimeout(function(){window.location.href='htcmd:loaded';},3000);"> 

Second: add code to web client:

@Override
public void onPageFinished(WebView view, String url) {
    if (android.os.Build.VERSION.SDK_INT >= 19) {
        view.requestFocus();
    }
}

1 Answer 1

2

try this

w.getSettings().setLoadWithOverviewMode(true);
w.getSettings().setUseWideViewPort(true);   
getWebView().getSettings().setJavaScriptEnabled(true);
getWebView().setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
           return (false);

    });
public void onReceivedError(WebView view, int errorCode, String description, String  failingUrl) {
                 Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
               }
    getWebView().loadUrl("https://www.google.com");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.