Skip to content Skip to sidebar Skip to footer

Android: Click Within Webview Causes Callback To Android Application

I'm thinking of implementing a HTML welcome panel to our Android app, which presents news and offers on the start-up screen. My question is now, if I present an offer to a specific

Solution 1:

It's probably better to use WebView.addJavascriptInterface, rather than overload onJsAlert.

Solution 2:

yes indeed you can good sir! If you show the data in a javascript Alert, then you can capture it like this. It might not be the most neat way, but it works =)

privatevoidloadWebViewStuff() {
        myWebView.setWebChromeClient(newMyWebChromeClient());
        myWebView.loadUrl(URL);
}


final classMyWebChromeClientextendsWebChromeClient {
    @OverridepublicbooleanonJsAlert(WebView view, String url, String message, JsResult result) {
        //"message" is what is shown in the alert, here we can do whatever with it
    }
}

Post a Comment for "Android: Click Within Webview Causes Callback To Android Application"