Skip to content Skip to sidebar Skip to footer

Android Web View To Android Java Activity Class

is it possible to make a html button that when I click, it will go to my android activity class. Just like using Intent when I view Activity to another Activity anyone have a thoug

Solution 1:

public class JavaScriptInterface {
Context mContext;

/** Instantiate the interface and set the context */
JavaScriptInterface(Context c) {
    mContext = c;
}

/** Show a toast from the web page */
public void showToast(String toast) {
    Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
}

 WebView webView = (WebView) findViewById(R.id.webview);
 webView.addJavascriptInterface(new JavaScriptInterface(this), "Android");

in java script

   <input type="button" value="Say hello" onClick="showAndroidToast('Hello Android!')" />

  <script type="text/javascript">
    function showAndroidToast(toast) {
    Android.showToast(toast);
   }
  </script>

Post a Comment for "Android Web View To Android Java Activity Class"