July 2015
Beginner to intermediate
600 pages
18h 59m
English
In this chapter, you have seen how to use WebViewClient and WebChromeClient to respond to specific events that happen in your WebView. However, it is possible to do even more than that by injecting arbitrary JavaScript objects into the document contained in the WebView itself. Check out the documentation at http://developer.android.com/reference/android/webkit/WebView.html and scroll down to the addJavascriptInterface(Object, String) method. Using this, you can inject an arbitrary object into the document with a name you specify.
mWebView.addJavascriptInterface(new Object() { @JavascriptInterface public void send(String message) { Log.i(TAG, "Received message: " + message); } ...Read now
Unlock full access