Is it possible to add a JavaScript interface to the Android Browser the same way one can be added to the WebView Component as illustrated in this demo. My particular use case only needs JavaScript -> android so that I can send it back to the previous activity.
You can invoke methods and functions in your webview by using javascript url's, e.g.
webview.loadUrl("javascript:somemethod()");
You will, of course, need to enable javascript on your webview:
webview.getSettings().setJavaScriptEnabled(true);
This is from java to javascript. If you want to invoke java code / android API's from javascript, use addJavascriptInterface()
webview.addJavascriptInterface(new MyJSJavaBridge(), "api");
All of this is shown in the example url you posted as well.
You can do it using jsinterface. First you need to make the browser jsinterface enabled and then you may call to Android method from the HTML of your browser.
You may , get a fair example and idea here ...
http://android-puremvc-ormlite.blogspot.com/2011/07/using-java-script-in-android-webview.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With