I am trying to pass JSON-formatted data from my Android WebView to a HTML page. However, the app crashes whenever I try to parse the original JSON data, which I am expecting
I copy pasted your code and it works (nothing is shown because you dont show the data) but the callback made from the Javascript into Android is executed correctly. You can check it with this code:
WebView mWebView = (WebView) findViewById(R.id.webView1);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.addJavascriptInterface(this, "webConnector");
mWebView.addJavascriptInterface(this, "toaster");
mWebView.loadUrl("file:///android_asset/table.html");
}
public String load() {
Log.e("HelloJavascript","HelloJavascript");
return "{\"key\":\"data\"}";
}
public void print(String message){
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}
And the HTML
<html>
<head>
<title>Test</title>
<script type="text/javascript">
function loader() {
var jsonData = window.webConnector.load();
toaster.print(jsonData);
}
</script>
</head>
<body onload="loader()">
Do nothing
</body>
</html>