From 0fe0748d095607128433a606c1976f441ea1dbda Mon Sep 17 00:00:00 2001 From: hypothermic Date: Sat, 22 Dec 2018 21:19:11 +0100 Subject: [PATCH] uri.getHost() can be null if the user clicks on mailto: links and phone numbers --- app/src/main/java/com/example/app/MyWebViewClient.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/example/app/MyWebViewClient.java b/app/src/main/java/com/example/app/MyWebViewClient.java index 2087cf1..fd88362 100755 --- a/app/src/main/java/com/example/app/MyWebViewClient.java +++ b/app/src/main/java/com/example/app/MyWebViewClient.java @@ -9,7 +9,8 @@ public class MyWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { - if (Uri.parse(url).getHost().endsWith("example.com")) { + Uri uri = Uri.parse(url); + if (uri.getHost() != null && uri.getHost().contains("example.com")) { return false; } @@ -17,4 +18,4 @@ public class MyWebViewClient extends WebViewClient { view.getContext().startActivity(intent); return true; } -} \ No newline at end of file +}