Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[webview_flutter] fix not working choose file #2245

Closed
wants to merge 2 commits into from
Closed

[webview_flutter] fix not working choose file #2245

wants to merge 2 commits into from

Conversation

crazecoder
Copy link

@crazecoder crazecoder commented Oct 30, 2019

Description

fix webview_flutter not working choose file
Only applicable to android5.0 or above

Related Issues

flutter/flutter#27924

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

Only applicable to android5.0 or above
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@crazecoder
Copy link
Author

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@crazecoder crazecoder changed the title fix #27924 fix webview_flutter not working choose file Oct 30, 2019
@crazecoder crazecoder changed the title fix webview_flutter not working choose file [webview_flutter] fix not working choose file Oct 30, 2019
@mantou132
Copy link

mantou132 commented Nov 9, 2019

I hope to merge soon.

How can I try this version in my project?

@NorbertSzydlowski
Copy link

Hello,
I have been select this fix. It is will crash when second time go to webview and select file.

E/AndroidRuntime(31232): FATAL EXCEPTION: main
E/AndroidRuntime(31232): Process: pl.cormo.ocenapolis, PID: 31232
E/AndroidRuntime(31232): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=18, result=-1, data=Intent { dat=content://com.android.providers.media.documents/document/image:13549 flg=0x1 }} to activity {pl.cormo.ocenapolis/pl.cormo.ocenapolis.MainActivity}: java.lang.IllegalStateException: showFileChooser result was already called
E/AndroidRuntime(31232): 	at android.app.ActivityThread.deliverResults(ActivityThread.java:4423)
E/AndroidRuntime(31232): 	at android.app.ActivityThread.handleSendResult(ActivityThread.java:4465)
E/AndroidRuntime(31232): 	at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
E/AndroidRuntime(31232): 	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
E/AndroidRuntime(31232): 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
E/AndroidRuntime(31232): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
E/AndroidRuntime(31232): 	at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(31232): 	at android.os.Looper.loop(Looper.java:201)
E/AndroidRuntime(31232): 	at android.app.ActivityThread.main(ActivityThread.java:6810)
E/AndroidRuntime(31232): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(31232): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
E/AndroidRuntime(31232): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
E/AndroidRuntime(31232): Caused by: java.lang.IllegalStateException: showFileChooser result was already called
E/AndroidRuntime(31232): 	at in.onReceiveValue(PG:8)
E/AndroidRuntime(31232): 	at io.flutter.plugins.webviewflutter.FlutterWebViewChromeClient.onActivityResult(FlutterWebViewChromeClient.java:204)
E/AndroidRuntime(31232): 	at io.flutter.app.FlutterPluginRegistry.onActivityResult(FlutterPluginRegistry.java:204)
E/AndroidRuntime(31232): 	at io.flutter.app.FlutterActivityDelegate.onActivityResult(FlutterActivityDelegate.java:132)
E/AndroidRuntime(31232): 	at io.flutter.app.FlutterActivity.onActivityResult(FlutterActivity.java:142)
E/AndroidRuntime(31232): 	at android.app.Activity.dispatchActivityResult(Activity.java:7590)
E/AndroidRuntime(31232): 	at android.app.ActivityThread.deliverResults(ActivityThread.java:4416)

@crazecoder
Copy link
Author

crazecoder commented Nov 22, 2019

@NorbertSzydlowski This is a known problem, it will go to the first filePathCallback every time, I think it has something to do with the mechanism of flutter, you can set up the public static filePathCallback in the WebViewFlutterPlugin to solve it, but I don't think it's an elegant solution

@NorbertSzydlowski
Copy link

@crazecoder Second problem is selected multiple files.

intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, allowMultiple);

It isn't correct get URI from Intent.
WebChromeClient.FileChooserParams.parseResult(resultCode, data)

I have been used this method (from flutter_webview_plugin):

private Uri[] getSelectedFiles(Intent data) {

        if (data == null) {
            return null;
        }

        if (data.getData() != null) {
            String dataString = data.getDataString();
            if (dataString != null) {
                return new Uri[]{Uri.parse(dataString)};
            }
        }

        if (data.getClipData() != null) {
            final int numSelectedFiles = data.getClipData().getItemCount();
            Uri[] result = new Uri[numSelectedFiles];
            for (int i = 0; i < numSelectedFiles; i++) {
                result[i] = data.getClipData().getItemAt(i).getUri();
            }
            return result;
        }

        return null;
    }

@fyeeme
Copy link

fyeeme commented Dec 18, 2019

@NorbertSzydlowski @crazecoder how to use this PR before it's merged?

@NorbertSzydlowski
Copy link

@fyeeme select PR as dependency
https://dart.dev/tools/pub/dependencies

@ismanong
Copy link

希望修复

@cazeredodev
Copy link

Is there any chance that the fix will be delivered in the next few days?

@sysmesh
Copy link

sysmesh commented Jan 29, 2020

Any progress? This issue is a REAL pain.

@deandreamatias
Copy link

deandreamatias commented Jan 29, 2020

Please stop commenting on problems

any update on this

The best option is to add this emoji 👍 in the initial comment.

To see a priority of each issue, we can see in which Milestone the issue is added. This issue belongs
to milestone Goals, with this description:

P2: These are tasks we think are worth fixing in the coming years. It includes issues we've identified that might block fully shipping broad consumer-facing apps, correctness issues, and bugs relating to polish and quality. The date on this milestone is utterly arbitrary and just intended to sort the milestone appropriately.

@stuartmorgan-g stuartmorgan-g added the p: webview_flutter Edits files for a webview_flutter plugin label Jan 29, 2021
@stuartmorgan-g
Copy link
Contributor

We apologize for the long delay in triaging this PR. We’re in the process of overhauling our PR triage system to respond much more quickly, as well as working through the backlog.

  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).

Per Flutter policy, this will need tests before it can move forward; I believe that means it is blocked on the webview_flutter portion of flutter/flutter#83358 since this would show native UI. We can revisit once that scaffolding is in place (and if anyone is interested in moving this forward, a PR to do that would gladly be accepted to accelerate the process).

Also, could you could elaborate on the discussion above? If this crashes when used more than once, then it doesn't sound like it's ready for review. Is there a blocking issue preventing fixing that crash?

@stuartmorgan-g
Copy link
Contributor

Since this hasn't received any updated based on the comment above, and since the Android implementation of the plugin has been very substantially changed since this PR was created, I'm going to close it as obsolete. If this is still something you are interested in implementing, please feel free to open a new PR! (Or, preferably, collaborate on #3225)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes p: webview_flutter Edits files for a webview_flutter plugin platform-android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants