Android - Passing JSON object from webview javascript to java
@njzk2 is right, do it like this:
In JAVA:
@JavascriptInterfacepublic String test(String data) { Log.d("TEST", "data = " + data); return "this is just a test";}
In JS:
// some code var result = test("{ a: 1, b: 2 }");alert(result);//some codefunction test(args) { if (typeof Android != "undefined"){ // check the bridge if (Android.test!= "undefined") { // check the method Android.test(args); } }}
You can use GSON library or similar to create Stringified JSON to Java object, and JSON.Stringify(data)
on JS side