Answer the question
In order to leave comments, you need to log in
Push notifications on WebView - how to implement in an Android application?
In my example, I connected the java functions of the application in Android Studio using the Javascript code on my site:
I connect the Javascript interface to the public MainActivity class:
myWebView.addJavascriptInterface(new WebAppInterface(this), "Android");
<input type="button" value="Say hello" onClick="showAndroidToast('Hello Android!')" />
<script type="text/javascript">
function showAndroidToast(toast) {
Android.showToast(toast);
}
</script>
public class WebAppInterface {
Context mContext;
WebAppInterface(Context c) {
mContext = c;
}
@JavascriptInterface
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question