0

We know Android studio can get invoke the html javascript since Android API17,

ERPWebViewJsInterface erpWebViewJsInterface = new ERPWebViewJsInterface(this);
erpWebViewJsInterface.setmWebViewJSCallBack(this);
webView.addJavascriptInterface(erpWebViewJsInterface, WebViewParams.WEBVIEWW_JS_FLAG);

Sometimes, we may need return data to html ,But the Javascript how to get the data?

I think, maybe we can in javascript define resultCallBack, when we get the result, we can invoke the Javascript method!

Do you have the better method! get the Android method return data?

1 Answer 1

1

The method addJavaScriptInterface is meant to call Java functions from JavaScript.

To call JavaScript code from Java you can't use that. You might want to use loadUrl instead.

For example:

webView.loadUrl("javascript:alert('Hey there!')"); 

You can replace the alert call with whatever code you need.

You could also do something similar using Apache Cordova. It allows you to call Java Plugins from JavaScript. You can pass a callback to a Cordova plugin, have the plugin cache the callback, and then run it from Java whenever you need it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.