I have a webview with an added javascript interface that works fine on most devices, except for those running Android 4.2.1.
I deleted most of the code and stayed with very simple code:
this.webView.getSettings().setJavaScriptEnabled(true); this.webView.setWebChromeClient(new WebChromeClient()); this.webView.addJavascriptInterface(new Object() { public void handshake() { Log.d("JS", "handshake no params"); } public void handshake(String json) { Log.d("JS", "handshake with params: " + json); } }, "Android");
In javascript, the side of the testing code looks like this:
Android.handshake();
But I get this in logcat:
E / Web Console: Not Prepared TypeError: Object [object Object] does not have a "handshake" method
Again, this same exact thing works great on devices that have older Android os versions (<4.2.1) that I tested (minimum version 2.3.3).
The strange thing is that if I start a completely new project, having only one action, having only WebView, with the same code, everything works fine even for 4.2.1, but when it is part of my actual project, everything breaks. I am not doing anything with a webview that is not included in these code snippets that I provided.
What's the strangest thing for me is that javascript finds an Android object, but it just doesn't have the requested method (handshake), how can it be?
Any help would be greatly appreciated, as it made me go crazy for the past 2 weeks or so (this is a mistake that I return all the time and then give up, etc.). Thank.
javascript android webview
Nitzan Tomer Dec 25 2018-12-12T00: 00Z
source share