-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix beforeload for Android <= 7 #427
Conversation
Most of the work is thanks to @caioinova. They figured out solution in #386. |
Any update on merging this PR? Facing the same issue. @RGTK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this change! getWebViewClient()
was indeed added in API level 26.
src/android/InAppBrowser.java
Outdated
@@ -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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O
, since the Android docs mention "added in API level 26".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better indeed. Done.
if(beforeload.equals("yes") | ||
if (beforeload.equals("yes") && method == null) { | ||
useBeforeload = true; | ||
}else if(beforeload.equals("yes") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean method
can be null
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, For Android 6 and below shouldOverrideUrlLoading(WebView webView, String url)
is called which calls shouldOverrideUrlLoading(String url, String method)
with null as 2nd argument due to lack of possibility of deducing HTTP method from bare URL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
|
@digistorm This PR handles yes/no values and is tested. Feel free to create another PR if you'd find it valuable. |
@wvengen Could it be merged then? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, afaik this can be merged!
@purplecabbage Would you find time to merge it? |
Platforms affected
Android
Motivation and Context
On Android <= 7, using
beforeload
would crash the application due to change of Android API.Fixes #386
Description
If device is running Android <= 7,
Testing
I ran it on Android 7 and 9, create
WebViewClient
instead of trying on relying onWebView#getWebViewClient()
which is not available in these versions.Checklist
(platform)
if this change only applies to one platform (e.g.(android)
) Already made a commit without such prefix. Squashing it during merge should solve the issue.