Fix beforeload for Android <= 7 (#427)

* Fix beforeload for Android <= 7
* Change Android version check conditional
This commit is contained in:
Ralph Gutkowski 2019-06-12 21:03:23 +02:00 committed by Jesse MacFadyen
parent a162bd9076
commit 94fec84d5c

View File

@ -148,6 +148,7 @@ public class InAppBrowser extends CordovaPlugin {
private String footerColor = ""; private String footerColor = "";
private String beforeload = ""; private String beforeload = "";
private String[] allowedSchemes; private String[] allowedSchemes;
private InAppBrowserClient currentClient;
/** /**
* Executes the request and returns PluginResult. * Executes the request and returns PluginResult.
@ -264,7 +265,12 @@ public class InAppBrowser extends CordovaPlugin {
@SuppressLint("NewApi") @SuppressLint("NewApi")
@Override @Override
public void run() { public void run() {
((InAppBrowserClient)inAppWebView.getWebViewClient()).waitForBeforeload = false; if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O) {
currentClient.waitForBeforeload = false;
inAppWebView.setWebViewClient(currentClient);
} else {
((InAppBrowserClient)inAppWebView.getWebViewClient()).waitForBeforeload = false;
}
inAppWebView.loadUrl(url); inAppWebView.loadUrl(url);
} }
}); });
@ -964,8 +970,8 @@ public class InAppBrowser extends CordovaPlugin {
} }
}); });
WebViewClient client = new InAppBrowserClient(thatWebView, edittext, beforeload); currentClient = new InAppBrowserClient(thatWebView, edittext, beforeload);
inAppWebView.setWebViewClient(client); inAppWebView.setWebViewClient(currentClient);
WebSettings settings = inAppWebView.getSettings(); WebSettings settings = inAppWebView.getSettings();
settings.setJavaScriptEnabled(true); settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setJavaScriptCanOpenWindowsAutomatically(true);
@ -1200,7 +1206,9 @@ public class InAppBrowser extends CordovaPlugin {
boolean useBeforeload = false; boolean useBeforeload = false;
String errorMessage = null; 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: //TODO handle POST requests then this condition can be removed:
&& !method.equals("POST")) && !method.equals("POST"))
{ {