boolean shouldOverrideUrlLoading (WebView view, String url)
deprecated in API 24, boolean shouldOverrideUrlLoading (WebView view, WebResourceRequest request)
added in API level 24
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
if(Uri.parse(request.getUrl().toString()).getHost().endsWith("google.com")) {
//The host application wants to leave the current WebView and handle the url itself.
return true;
}
if(Uri.parse(request.getUrl().toString()).getHost().endsWith("yandex.com")) {
//The current WebView handles the url.
return false;
}
if(Uri.parse(request.getUrl().toString()).getScheme().equals("file")) {
//The current WebView handles the url.
return false;
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(request.getUrl().toString()));
view.getContext().startActivity(intent);
return true;
}