Issue
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 thoughts?
my JsInteface class change into this
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) {
Intent mainIntent = new Intent(mContext, echos.class);
mContext.startActivity(mainIntent);
}
}
Solution
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>
Answered By - Athul Harikumar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.