Skip to content

Instantly share code, notes, and snippets.

@fatihkurcenli
Created August 19, 2020 18:59
Show Gist options
  • Save fatihkurcenli/2118f5341f3f4f7d67200e2254613811 to your computer and use it in GitHub Desktop.
Save fatihkurcenli/2118f5341f3f4f7d67200e2254613811 to your computer and use it in GitHub Desktop.
public class MyWebViewClient extends 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
public void onSafeBrowsingHit(WebView view, WebResourceRequest request,
int threatType, SafeBrowsingResponse callback) {
// The "true" argument indicates that your app reports incidents like
// this one to Safe Browsing.
callback.backToSafety(true);
Toast.makeText(view.getContext(), "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