Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebView doesn't show JSAlert on Lollipop devices

It wasn't showing JSAlert on any devices. And then I set a WebChromeClient:

webView.setWebChromeClient(new WebChromeClient() {

            @Override
            public boolean onJsAlert(WebView view, String url, String message,
                    JsResult result) {
                return super.onJsAlert(view, url, message, result);
            }

            @Override
            public boolean onJsPrompt(WebView view, String url, String message,
                    String defaultValue, JsPromptResult result) {
                return super.onJsPrompt(view, url, message, defaultValue,
                        result);
            }

        });

Now it works fine on all pre-Lollipop devices. And doesn't show any alert on Lollipop devices.

Logcat says "Cannot create a dialog, the WebView context is not an Activity".

like image 320
Seshu Vinay Avatar asked Apr 09 '15 05:04

Seshu Vinay


1 Answers

There is a bug introduced in version 40 of WebView, and is fixed in version 42.

Check the issue reported at

https://code.google.com/p/chromium/issues/detail?id=478204

like image 117
Pavan Andhukuri Avatar answered Nov 15 '22 18:11

Pavan Andhukuri