android - Webview not showing JavaScript alerts - Stack Overflow

We built a hybrid application using android webview and I use my phone (LG Nexus 4) to test it. The and

We built a hybrid application using android webview and I use my phone (LG Nexus 4) to test it. The android application used to show JavaScript alerts from the website properly earlier but lately it has stopped showing the same.

It is throwing the following error whenever an alert is to be thrown from the application and nothing is shown.

 Cannot create a dialog, the WebView context is not an Activity

I am suspecting that this behaviour has started after google has recently updated the WebView ponent. I am right now running on Android 5.0.1 and webview version is 40 (1832189-arm)

I will try rolling back the updates and check but I can't ask all the users to do it. Are there any other issues reported similar to this? Is there a solution?

Update I have uninstalled the updates to the WebView ponent and checked. Alerts are being shown fine. If this is an issue, where can I report it?

We built a hybrid application using android webview and I use my phone (LG Nexus 4) to test it. The android application used to show JavaScript alerts from the website properly earlier but lately it has stopped showing the same.

It is throwing the following error whenever an alert is to be thrown from the application and nothing is shown.

 Cannot create a dialog, the WebView context is not an Activity

I am suspecting that this behaviour has started after google has recently updated the WebView ponent. I am right now running on Android 5.0.1 and webview version is 40 (1832189-arm)

I will try rolling back the updates and check but I can't ask all the users to do it. Are there any other issues reported similar to this? Is there a solution?

Update I have uninstalled the updates to the WebView ponent and checked. Alerts are being shown fine. If this is an issue, where can I report it?

Share Improve this question asked Apr 16, 2015 at 11:43 Pavan AndhukuriPavan Andhukuri 1,6173 gold badges27 silver badges49 bronze badges 4
  • dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); dialog.show(); – Rahul Commented Apr 16, 2015 at 11:48
  • I think you have to report on play store. – Hareshkumar Chhelana Commented Apr 16, 2015 at 11:48
  • @Rah, and "dialog" is? – Pavan Andhukuri Commented Apr 16, 2015 at 11:51
  • AlertDialog for onJsAlert. – Rahul Commented Apr 16, 2015 at 12:31
Add a ment  | 

3 Answers 3

Reset to default 4

To get JavaScript Alert to work on Android WebView add below line of code:

mWebView.setWebChromeClient(new WebChromeClient());

After following Line of code:

webSettings.setJavaScriptEnabled(true);

Finally it Should look like:

webSettings.setJavaScriptEnabled(true);
mWebView.setWebChromeClient(new WebChromeClient());

Here is the answer from JavaScript alert not working in Android WebView Check this link , and last ment , You have to use WebChromeClient for your purpose.

http://code.google./p/android/issues/detail?id=752

This seems to be a bug introduced into build 40 of WebView. It is fixed in version 42 as per the issue I've logged.

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745229109a4617598.html

相关推荐

  • android - Webview not showing JavaScript alerts - Stack Overflow

    We built a hybrid application using android webview and I use my phone (LG Nexus 4) to test it. The and

    4小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信