-
Notifications
You must be signed in to change notification settings - Fork 2.2k
CB-9148 - (android) Add support for input[type=file] to InAppBrowser! #205
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
Conversation
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.
There's some minor changes that need to be done before we can accept this, such as using the cordova.startActivityForResult method instead of grabbing the Activity, but once that cleanup is done, I'm fine with this being added.
Reminder: Cordova does not support Android versions lower than Jellybean, which is Android 4.1. We don't need code for anything lower unless it's absolutely required.
src/android/InAppBrowser.java
Outdated
|
|
||
| // [important] Register ActvityResultCallback on Cordova | ||
| cordova.setActivityResultCallback(InAppBrowser.this); | ||
| cordova.getActivity().startActivityForResult(content, FILECHOOSER_REQUESTCODE_LOLLIPOP); |
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.
This should be using the Plugin API's startActivityForResult where you pass in the plugin that you're sending the Activity to. Doing this is actually very unstable, and can be unpredictable since other plugins also use Intents.
src/android/InAppBrowser.java
Outdated
| i.addCategory(Intent.CATEGORY_OPENABLE); | ||
|
|
||
| cordova.setActivityResultCallback(InAppBrowser.this); | ||
| cordova.getActivity().startActivityForResult( Intent.createChooser(i, "File Chooser"), FILECHOOSER_REQUESTCODE); |
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.
This should also be using the plugin API to start the activity for result.
| // Call file chooser for Android 3.0+ | ||
| openFileChooser(uploadMsg, ""); | ||
| } | ||
|
|
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.
Why does this need to be here? We do not support any versions of Android below Android 4.1, so this would never be called.
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.
Well, latest cordova-android doesn't support Android versions below 4.1, but the plugin can be used with older versions of cordova-android as we have the engine set to cordova >=3.1.0. We should bump the engine version to the one that started setting the SDK version to 16 if we are not going to support older Android versions in plugins.
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.
@jcesarmobile In this case, this method is supporting versions of Android below 3.0, and we don't have a version of Cordova that we support or maintain that uses this. (We dropped Gingerbread years ago to much fanfare!!)
For some reason the version that supports 3.0 and higher is the primary method, so we have to keep it, but I have no idea why this method is needed.
src/android/InAppBrowser.java
Outdated
| // For Android 5.0+ | ||
| public boolean onShowFileChooser (WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) | ||
| { | ||
| Log.d(LOG_TAG, "File Chooser 5.0+"); |
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.
We use LOG instead of Log to use Cordova LOG instead of default Log, so it can be disabled with a preference.
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'm going to open an issue to create an Android Style Guide or something. I kinda feel bad we're being this nit-picky on someone's first PR. (I'm still going to do it, because we're supposed to, but still)
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.
@infil00p It's okay because I'm really enjoying this process :)
I am the person who loves stable and beautiful codes.
Thanks for all the comments and interests about my suggestion!
I'm newbie here, but I'll try hard to be a good contributor here :D
|
@infil00p |
|
@darron1217 Looks good! Did you get the iCLA in? Once you do that, I'll merge this. |
|
Congrats on your first major contribution to Cordova! Well done! |
|
@infil00p Thank you for your guidance :) |
|
Does not seem to work for me on Android 4.3. When I try to choose a file for an input[type=file] field, I get an "application for this action cannot be found" error. |
|
@markusjwetzel I've just tested it on Android 4.4 and as you said, it isn't working... --> I realized that Android removed the openfilechooser function from Kitkat 4.4.2 which is version that I've tested... |
|
@markusjwetzel Did you tested it on real device? |
|
@markusjwetzel @darron1217 Technically, this won't work on any version of Android below API Level 21: And, Google didn't remove the functionality, in fact they added it with the 5.0.x release. Before 5.0, this functionality didn't even exist. This issue should really exist in another JIRA issue, although due to it only affecting 4.4 and below, it would be listed as a low priority issue. |
|
@infil00p I agree, this should be a new issue. @darron1217, BTW, you can take a look into the implementation in the Cordova webview, I think it works fine with Android 4.3 |
|
@darron1217 Yes, I tested it on a real device. |
|
@infil00p @jcesarmobile Thanks for all the comments :) |
|
@markusjwetzel Can you share your detailed error log? |
|
Sorry, really new to app development, so I don't know how to get an error log from a real device and don't really have time to figure that out. But I guess that this error can be reproduced easily. The error was translated from German. So the official English version might differ a bit, but at least the meaning should be the same. Hope that helps a little bit. 😃 |
Patch in changes from apache#205
|
Unfortunately, this is also not working for me. I updated `inappbrowser to the latest: Which should include this change, but the file input is still not opening the native file browser. The same code works fine in iOS (#139). I'm wondering if I'm missing something, maybe a conflicting plugin? I'm testing it through the PhoneGap Android version, can it be a thing? |
That was it. It's working fine after building the app. The issue was with the PhoneGap app, which is probably not running the latest. |
|
Hello, I am still having the issue with the android. Is this issue fixed/ included in the cordova? |
|
It's included in cordova-plugin-inappbrowser 1.7.0. Note though that it will not work on certain Android versions, notably 4.4.2, as shown below. I don't know about before that. On a Samsung S3 with 4.3 I got something like "There's no associated app...", which is something else. I use PhoneGap Build and it invokes 1.7.1 of the plugin. Hopefully someone knows what versions the fix works on. _@markusjwetzel I've just tested it on Android 4.4 and as you said, it isn't working... --> I realized that Android removed the openfilechooser function from Kitkat 4.4.2 which is version that I've tested... |
Platforms affected
Android
What does this PR do?
This PR enables default action for input[type=file] at inappbrowser.
Which means, input[type=file] opens native file chooser in android.
What testing has been done on this change?
I tested input[type=file] element to open file chooser.
And it worked beautifully :D
Checklist