diff --git a/android/capacitor/src/main/java/com/getcapacitor/Bridge.java b/android/capacitor/src/main/java/com/getcapacitor/Bridge.java index b17682b2a8..f6c257de31 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/Bridge.java +++ b/android/capacitor/src/main/java/com/getcapacitor/Bridge.java @@ -173,7 +173,7 @@ public Bridge(Activity context, WebView webView, List> i } private void loadWebView() { - appUrlConfig = this.config.getString("server.url"); + appUrlConfig = this.getServerUrl(); String[] appAllowNavigationConfig = this.config.getArray("server.allowNavigation"); ArrayList authorities = new ArrayList(); @@ -182,7 +182,7 @@ private void loadWebView() { } this.appAllowNavigationMask = HostMask.Parser.parse(appAllowNavigationConfig); - String authority = this.config.getString("server.hostname", "localhost"); + String authority = this.getHost(); authorities.add(authority); String scheme = this.getScheme(); @@ -341,6 +341,22 @@ public String getScheme() { return this.config.getString("server.androidScheme", CAPACITOR_HTTP_SCHEME); } + /** + * Get host name that is used to serve content + * @return + */ + public String getHost() { + return this.config.getString("server.hostname", "localhost"); + } + + /** + * Get the server url that is used to serve content + * @return + */ + public String getServerUrl() { + return this.config.getString("server.url"); + } + public CapConfig getConfig() { return this.config; } diff --git a/android/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java b/android/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java index d632065a9d..44bccc328e 100755 --- a/android/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java +++ b/android/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java @@ -172,7 +172,7 @@ public WebResourceResponse shouldInterceptRequest(WebResourceRequest request) { return null; } - if (isLocalFile(loadingUrl) || (bridge.getConfig().getString("server.url") == null && !bridge.getAppAllowNavigationMask().matches(loadingUrl.getHost()))) { + if (isLocalFile(loadingUrl) || loadingUrl.getHost().equalsIgnoreCase(bridge.getHost()) || (bridge.getServerUrl() == null && !bridge.getAppAllowNavigationMask().matches(loadingUrl.getHost()))) { Logger.debug("Handling local request: " + request.getUrl().toString()); return handleLocalRequest(request, handler); } else {