Skip to content
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

Merged
merged 2 commits into from
Jun 12, 2019

Conversation

nounder
Copy link
Contributor

@nounder nounder commented Feb 14, 2019

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 on WebView#getWebViewClient() which is not available in these versions.

Checklist

  • I've run the tests to see all new and existing tests pass
  • I added automated test coverage as appropriate for this change
  • Commit is prefixed with (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.
  • If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • I've updated the documentation if necessary

@nounder
Copy link
Contributor Author

nounder commented Feb 14, 2019

Most of the work is thanks to @caioinova. They figured out solution in #386.

@clark-zhao-hs
Copy link

Any update on merging this PR? Facing the same issue. @RGTK

Copy link
Contributor

@wvengen wvengen left a 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.

@@ -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) {
Copy link
Contributor

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".

Copy link
Contributor Author

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")
Copy link
Contributor

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?

Copy link
Contributor Author

@nounder nounder Mar 11, 2019

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.

Copy link
Contributor

@wvengen wvengen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@digistorm-developer
Copy link

customizableOptions should include BEFORELOAD otherwise post and get will get cast to a yes or no value.

@nounder
Copy link
Contributor Author

nounder commented Jun 6, 2019

@digistorm This PR handles yes/no values and is tested. Feel free to create another PR if you'd find it valuable.

@nounder
Copy link
Contributor Author

nounder commented Jun 6, 2019

@wvengen Could it be merged then?

Copy link
Contributor

@wvengen wvengen left a 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!

@nounder
Copy link
Contributor Author

nounder commented Jun 12, 2019

@purplecabbage Would you find time to merge it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error on Android 6 and 7 using plugin from master
5 participants