Skip to content

Instantly share code, notes, and snippets.

@fatihkurcenli
Created August 19, 2020 18:58
Show Gist options
  • Save fatihkurcenli/8c4bb64c2a286181ed7011c373e43e12 to your computer and use it in GitHub Desktop.
Save fatihkurcenli/8c4bb64c2a286181ed7011c373e43e12 to your computer and use it in GitHub Desktop.
class MyWebViewClient : WebViewClient() {
// Automatically go "back to safety" when attempting to load a website that
// Safe Browsing has identified as a known threat. An instance of WebView
// calls this method only after Safe Browsing is initialized, so there's no
// conditional logic needed here.
override fun onSafeBrowsingHit(
view: WebView,
request: WebResourceRequest,
threatType: Int,
callback: SafeBrowsingResponse
) {
// The "true" argument indicates that your app reports incidents like
// this one to Safe Browsing.
callback.backToSafety(true)
Toast.makeText(view.context, "Unsafe web page blocked.", Toast.LENGTH_LONG).show()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment