[android]Java script to Java native Bindings & vice versa
<p>I am a working on developing web applications where we are trying to access Native functionality in the phone using Java script APIs.</p>

<p>Android Web view supports "AddJavascript" interface for Java script to Java (native) bindings as in below link</p>

<p><a href="http://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface(java.lang.Object" rel="nofollow">http://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface(java.lang.Object</a>, java.lang.String)</p>

<p>BUT if I need to pass data back to Java script there is no API or mechanism to do so in Android.
Could any please let me know if there is a way out, tried hard using JSON as below by we cannot pass all kinds of values using JSON</p>

<p>HTML with JS</p>

<pre><code>&lt;script id="source" language="javascript" type="text/javascript"&gt;
    function OnClick(){    
    var nativeStr = window.native.getValue();
    window.native.callBack();
    }

function JScallback(data) {
}
&lt;/script&gt;


WebView wv = (WebView) findViewById(R.id.MyWebView);

NativeClass myNative = new NativeClass (wv);

wv.getSettings().setJavaScriptEnabled(true);
wv.addJavascriptInterface(myNative, "native");
wv.loadUrl("file:///html/test.html");

public class NativeClass{

private WebView mWebView;

public NativeClass  (WebView appView) {
    this.mWebView = appView;
}

public String getValue() {
    return "Native Value";
}  


public void callBack() {
JSONArray arr = new JSONArray();

JSONObject result = new JSONObject();
try {
    result.put("Name", "Android Dev"); 
    arr.put(result);
} catch (Exception ex) {

}       

mWebView.loadUrl("javascript:JScallback(" + arr.toString() + ")");

}
</code></pre>

<p>Thanks in advance,
Android Dev.</p>
