From 717d7e882591d322eea9b64686c3921930ca97a1 Mon Sep 17 00:00:00 2001 From: slymax Date: Sun, 29 Mar 2020 18:26:24 +0200 Subject: [PATCH] simplify config --- README.md | 6 +++--- app/src/main/java/com/example/app/MyWebViewClient.java | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6153b62..ae16a29 100755 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This is a template project for Android Studio that allows you to create an andro ### Using a remote source -If you want to create an app that displays the content of a remote website +If you want to create an app that shows the content of a remote website 1. uncomment line **24** in `MainActivity.java` and replace `https://example.com` with your remote source @@ -14,10 +14,10 @@ If you want to create an app that displays the content of a remote website mWebView.loadUrl("https://example.com"); ``` -2. open the `MyWebViewClient.java` file and replace `example.com` on line **13** with your custom hostname +2. open the `MyWebViewClient.java` file and replace `example.com` on line **13** with your hostname ```java - if (url.startsWith("file:") || uri.getHost() != null && uri.getHost().endsWith("example.com")) { + hostname = "example.com"; ``` ### Using a local source diff --git a/app/src/main/java/com/example/app/MyWebViewClient.java b/app/src/main/java/com/example/app/MyWebViewClient.java index e32b5fb..8f6c392 100755 --- a/app/src/main/java/com/example/app/MyWebViewClient.java +++ b/app/src/main/java/com/example/app/MyWebViewClient.java @@ -9,8 +9,10 @@ class MyWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { + String hostname; + hostname = "example.com"; Uri uri = Uri.parse(url); - if (url.startsWith("file:") || uri.getHost() != null && uri.getHost().endsWith("example.com")) { + if (url.startsWith("file:") || uri.getHost() != null && uri.getHost().endsWith(hostname)) { return false; } Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));