Closed ghost closed 8 years ago
@shripalsoni04 inside my webview there is no window.androidWebViewInterface object, maybe thats the reason?
@einicher I tried to run your code in this demo app on android 6.0. It is working properly there. I have run the app with nativescript version 2.1.1.
Can you please try to clone that demo app, and run on android 6.0.1 with latest version of nativescript and runtime. If demo app works, just add your code in that app and check it.
If your code works proper in the demo app, then upgrade tns-core-modules
package and remove/add android platform in your project. This should resolve the issue.
Hope this will help.
Adding new languages works, but the two buttons beneath do nothing. "tns-android":"version": "2.1.1" "tns-core-modules": "^2.1.0"
Thanks for testing the demo app.
Actually I tested it yesterday on both emulator and device for android 6.0. It was working fine there. So it is strange why it is not working.
I will try to test it with android 6.0.1. Also, can you please tell me are you testing on emulator or device?
device, but will test it with emulator and over the mac too.
Happened to my side as well on Android 5.0. However, it did work (intermittently) when I added alert() code in native side.
BTW, I also noticed that alert() code in the webview does not work. And from an answer found in SO is due to this line: webView.setWebChromeClient(new WebChromeClient());
Perhaps is this related?
@shripalsoni04 Looks like there's a timing (race condition) that the .on() maybe too early. Perhaps some initialized event to hook on before the on() to be executed?
I just pushed android code for this plugin. As I am still not able to replicate this issue at my end, you can experiment at your end by modifying the java code.
Code and Instruction to generate .jar file can be found at https://github.com/shripalsoni04/android-webview-interface.
Hope this will help you.
Finally I was able to reproduce this issue on one android device. The issue was, sometimes the web-view is getting loaded before the plugin sets javascriptInterface to setup communication from web-view to android. And if javascriptInterface is set after web-view is loaded, it will not be accessible in web-view, which results in issue of communication from web-view to android sometime.
I have created a patch in version 1.3.1
and added src
parameter in WebViewInterface
constructor. To make it work on all devices, instead of setting src
in xml file, you need to set it by passing it as argument in the constructor as shown below:
var webViewInterface = new webViewInterfaceModule.WebViewInterface(webView, '~/www/index.html');
I have also updated the demo app to demonstrate this change.
Check below diff of sample demo app to understand it quickly.
main-page.xml
https://github.com/shripalsoni04/nativescript-webview-interface-demo/commit/64725b9f8ba48470acf9bc28e5d7b364fe7d9930#diff-585f95637116edda1e0b367ddbfbc6f1L5
So just update the plugin to latest version and do the above mentioned changes.
Thanks a lot @einicher and @davistan for raising this issue.
Your demo app works, but my app still does not. Is it possible the reason is, because I have the WebView in A TabView?
ok, it works now, reason seemed to be the segmented bar.
Hi,
in the app i do;
in the webview:
nothing happens.
i also do in app:
That works partially: initMap is getting called in the webview, but the success callback is never called.
It seems, native to webview is working fine, but from webview back to native not at all.
What could that be?
edit: on ios the code works perfectly fine, android version is 6.0.1