Skip to content Skip to sidebar Skip to footer

What Are Valid Return Values For A Javascript Interface On An Android Webview?

I have an Android WebView that has JavaScript that is calling Android methods through the addJavascriptInterface method: myWebview.addJavascriptInterface(new JavascriptBridge(), 'A

Solution 1:

I have not seen a list of valid types (for passing values to Java functions and to return), but only primitives and string seem to work.

You can use JSON (e.g. stringify and parse in Javascript, check various Java options at json.org

Solution 2:

You can return anything, primitives or Objects. Objects are converted to strings via their toString() method. If the JavascriptInterface method returns a JSON string (e.g. an Object who's toString() outputs JSON) you can then parse that string directly:

var array = JSON.parse(window.android.getSomeJsonThing());

Post a Comment for "What Are Valid Return Values For A Javascript Interface On An Android Webview?"