I have a webview that ignores all of my javascript front-end methods, or at least seems to be. When I launch the website from a normal browser, it throws errors because the interface is not defined, as expected, but it makes me think that the methods of the interface are at least being called, but something else is wrong. Can someone help me figure out what?
Material Announcement
@Override protected void onPostExecute(ValidationResult validation) { if (validation.wasSuccessful) { URL = validation.message; wv = (WebView) findViewById(R.id.webView); wv.addJavascriptInterface(new KioskInterface(wv.getContext()), "Android"); WebSettings ws = wv.getSettings(); ws.setJavaScriptEnabled(true); wv.loadUrl(URL); } else { errorAlert(title, msg + "\nContact network management."); } }
Kiosk Interface Class
public class KioskInterface { Context c; KioskInterface(Context context) { c = context; } @JavascriptInterface public void showToast() { Toast.makeText(c, "Hiding Keyboard", Toast.LENGTH_LONG).show(); } }
Javascript
function example() { Android.showToast(); }
I never see Toast, but I also have no mistakes or breakdowns.
source share