title: calling a javascript function from android
body: <p>I'm trying to call a javascript function from java android code. i tried to look at all previous questions concerning this but nothing seems to be working. are there any suggestions? thanks!</p>
  
  <pre><code>javascript code:
  &lt;html&gt;
      &lt;head&gt;
          &lt;script language="javascript"&gt;
              function doSomething() {
                  alert('hey!!!!!!!');
              }
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          ilana
      &lt;/body&gt;
  &lt;/html&gt;
  
  
  
  
  java code (from an activity on create)
  
   final WebView webview=(WebView)findViewById(R.id.myWebView);
   webview.getSettings().setJavaScriptEnabled(true);
   webview.addJavascriptInterface(new JavaScriptInterface(this), "Android");
   webview.loadUrl("file:///android_asset/www/index.html");
   webview.setWebChromeClient(new WebChromeClient());
   webview.loadUrl("javascript:doSomething()");
  </code></pre>
  
  <p>my updated (but still not working) code is:
  javascript:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script type="text/javascript"&gt;
      function doSomething(){
          alert("hello");
      }
  &lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  hello hello hello!
  &lt;/body&gt;
  &lt;/html&gt;
  
  java:
      final WebView webview=(WebView)findViewById(R.id.myWebView);
      webview.getSettings().setJavaScriptEnabled(true);
      webview.loadUrl("file:///android_asset/www/index.html");
      webview.setWebChromeClient(new WebChromeClient());
      webview.setWebViewClient(new WebViewClient(){
      @Override
      public void onPageFinished(WebView view, String url) {
           super.onPageFinished(view, url);
       view.loadUrl("javascript:doSomething()");
       }
  
      });
  </code></pre>