Here it is, just a simple way, suppose you have the following activity code with an interface, see the following code ...
public class htmldecoder extends Activity implements OnClickListener,TextWatcher { Button btsubmit; // this button in your xml file WebView wvbrowser; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.htmldecoder); btsubmit=(Button)findViewById(R.id.btsubmit); btsubmit.setOnClickListener(this); wvbrowser=(WebView)findViewById(R.id.wvbrowser); wvbrowser.setWebViewClient(new HelloWebViewClient()); wvbrowser.getSettings().setJavaScriptEnabled(true); wvbrowser.getSettings().setPluginsEnabled(true); wvbrowser.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); MyJavaScriptInterface myinterface=new MyJavaScriptInterface(); wvbrowser.addJavascriptInterface(myinterface,"interface"); webView.loadUrl("file:///android_asset/simple.html"); //use one html file for //testing put your html file in assets. Make sure that you done JavaScript methods to get //values for html content in html file . } public void onClick(View v) { if(btsubmit==v) { webView.loadUrl("javascript:showalert()");// call javascript method. //wvbr } } final class MyJavaScriptInterface { MyJavaScriptInterface() { } public void sendValueFromHtml(String value) { System.out.println("Here is the value from html::"+value); } } }
If you look at this code, you will find that I added an interface (MyJavaScriptInterface) in webview
wvbrowser.addJavascriptInterface(myinterface,"interface");
Now you need to write javascript in html
<script type="text/javascript"> //<![CDATA[ var n1; function callme(){ n1=document.getElementById("FacadeAL").value; } function showalert(){ window.interface.sendValueFromHtml(n1);// this method calling the method of interface which //you attached to html file in android. // & we called this showalert javasript method on //submmit buttton click of android. } //]]> </script>
& Make sure you call callme as below in html
<input name="FacadeAL" id="FacadeAL" type="text" size="5" onblur="callme()"/>
I hope you understand how it works. Let this help you pass your json array.
source share