From 55f0df537de3f949ff5bb490b6189c2ba2990567 Mon Sep 17 00:00:00 2001 From: Ralph Gutkowski Date: Thu, 14 Feb 2019 16:46:18 +0100 Subject: [PATCH 1/2] Fix beforeload for Android <= 7 --- src/android/InAppBrowser.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index 895b5436d..ec564b8d6 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -146,6 +146,7 @@ public class InAppBrowser extends CordovaPlugin { private String footerColor = ""; private String beforeload = ""; private String[] allowedSchemes; + private InAppBrowserClient currentClient; /** * Executes the request and returns PluginResult. @@ -262,7 +263,12 @@ else if (action.equals("loadAfterBeforeload")) { @SuppressLint("NewApi") @Override public void run() { - ((InAppBrowserClient)inAppWebView.getWebViewClient()).waitForBeforeload = false; + if (android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.N_MR1) { + currentClient.waitForBeforeload = false; + inAppWebView.setWebViewClient(currentClient); + } else { + ((InAppBrowserClient)inAppWebView.getWebViewClient()).waitForBeforeload = false; + } inAppWebView.loadUrl(url); } }); @@ -948,8 +954,8 @@ public void openFileChooser(ValueCallback uploadMsg, String acceptType) } }); - WebViewClient client = new InAppBrowserClient(thatWebView, edittext, beforeload); - inAppWebView.setWebViewClient(client); + currentClient = new InAppBrowserClient(thatWebView, edittext, beforeload); + inAppWebView.setWebViewClient(currentClient); WebSettings settings = inAppWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); @@ -1184,7 +1190,9 @@ public boolean shouldOverrideUrlLoading(String url, String method) { boolean useBeforeload = false; String errorMessage = null; - if(beforeload.equals("yes") + if (beforeload.equals("yes") && method == null) { + useBeforeload = true; + }else if(beforeload.equals("yes") //TODO handle POST requests then this condition can be removed: && !method.equals("POST")) { From 6e4804742d76e54e4be16375255b2a9d125be350 Mon Sep 17 00:00:00 2001 From: Ralph Date: Mon, 11 Mar 2019 13:03:56 +0100 Subject: [PATCH 2/2] Change Android version check conditional --- src/android/InAppBrowser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index ec564b8d6..c478aebb3 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -263,7 +263,7 @@ else if (action.equals("loadAfterBeforeload")) { @SuppressLint("NewApi") @Override public void run() { - if (android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.N_MR1) { + if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O) { currentClient.waitForBeforeload = false; inAppWebView.setWebViewClient(currentClient); } else {