title: Calling javascript function from native android activity code
body: <p>I have following Test Android App.</p>
  
  <pre><code>public class TestActivity extends Activity {
      @Override
      public void onCreate(Bundle savedInstanceState) {       
          super.onCreate(savedInstanceState);
  
          setContentView(R.layout.main);
  
          WebView webView = (WebView)findViewById(R.id.webView);
          webView.getSettings().setJavaScriptEnabled(true);
          webView.setWebChromeClient(new WebChromeClient());
          webView.loadUrl("file:///android_asset/www/test.html");        
     }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          getMenuInflater().inflate(R.menu.sudoku, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
      // Need to call javascript function testFun() here (see test.html)
    }
  }
  </code></pre>
  
  <p>Code for test.html</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
    &lt;head&gt;
    &lt;title&gt;Test&lt;/title&gt;
    &lt;meta charset="UTF-8" /&gt;
    &lt;script type="text/javascript"&gt;
      function testFun()
       {
         alert('Hi');
      }
    &lt;/script
    &lt;body&gt;
          &lt;button type="button" onclick="testFun()"&gt;Test&lt;/button&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I read about calling android functions in javascript <a href="http://developer.android.com/guide/webapps/webview.html" rel="nofollow">http://developer.android.com/guide/webapps/webview.html</a> </p>
  
  <p>But could not get how to call javascript functions from android (menu item click).</p>