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 filter multiple MIME types not work in android #50

Closed
wants to merge 3 commits into from

Conversation

fschai89
Copy link

The filter multiple MIME types work in IOS but not work in android, so I fix it.

DocumentPicker.show({filetype: [ /multiple mime type/ ]})

Example:

var docIdentifier = (Platform.OS === 'android') ? "application/msword" : "com.microsoft.word.doc"
                var docxIdentifier = (Platform.OS === 'android') ? "application/vnd.openxmlformats-officedocument.wordprocessingml.document" : "org.openxmlformats.wordprocessingml.document"
                var xlsIdentifier = (Platform.OS === 'android') ? "application/vnd.ms-excel" : "com.microsoft.excel.xls"
                var xlsxIdentifier = (Platform.OS === 'android') ? "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" : "org.openxmlformats.spreadsheetml.sheet"

                DocumentPicker.show({
                    filetype: [DocumentPickerUtil.plainText(), DocumentPickerUtil.pdf(), docIdentifier, docxIdentifier, xlsIdentifier, xlsxIdentifier],
                }, (error, url) => {
                    alert(url);
                });

Eg: 
DocumentPicker.show({
                    filetype: [DocumentPickerUtil.plainText(), DocumentPickerUtil.pdf(), docIdentifier, docxIdentifier, xlsIdentifier, xlsxIdentifier],
                }, (error, url) => {
                    alert(url);
                });
@Elyx0
Copy link
Collaborator

Elyx0 commented Jul 22, 2017

If I can get another look at it by an android dev that'd be nice

@Jaessun
Copy link

Jaessun commented Aug 21, 2017

I'm not an android dev but after taking a look at the code and testing it I can say it looks pretty good and works like a charm.

The only thing I'm not sure is the replacing of ACTION_OPEN_DOCUMENT by ACTION_GET_CONTENT.

The documentation states this:

ACTION_OPEN_DOCUMENT is not intended to be a replacement for ACTION_GET_CONTENT. The one you should use depends on the needs of your app:

  • Use ACTION_GET_CONTENT if you want your app to simply read/import data. With this approach, the app imports a copy of the data, such as an image file.
  • Use ACTION_OPEN_DOCUMENT if you want your app to have long term, persistent access to documents owned by a document provider. An example would be a photo-editing app that lets users edit images stored in a document provider.

In this case I don't really know which one is better. ACTION_OPEN_DOCUMENT is not supported before KitKat but neither is react native anyway. @fschai89 could you please explain?

Remove Android version checking since Intent.ACTION_GET_CONTENT work for Android 16 and above. And also fix for library not work for Android 18 and below.
@dantman
Copy link
Collaborator

dantman commented Sep 20, 2017

My 2 cents. I'm importing rather than opening documents, so personally this library not using ACTION_OPEN_DOCUMENT is one of the two reasons I discarded this library and wrote my own internal one.

Though given that iOS also has its own .open, .import, .exportToService, .moveToService modes perhaps the solution is to make this a configuration option.

@dantman
Copy link
Collaborator

dantman commented Sep 20, 2017

Actually the current usage of ACTION_OPEN_DOCUMENT/ACTION_PICK is wrong.

The iOS side of this library currently only uses .import, it doesn't support .open. Which is different than the semantics of ACTION_OPEN_DOCUMENT.

Falling back to ACTION_PICK is also wrong since it's intended to be used with a media provider URI, not just a type. You use ACTION_GET_CONTENT when you want to get something of a type.

@Elyx0
Copy link
Collaborator

Elyx0 commented Sep 27, 2017

I rather have 100% certainty of nothing breaking before merging :/

@dantman dantman mentioned this pull request Oct 14, 2017
25 tasks
@dantman dantman self-assigned this Oct 14, 2017
@dantman
Copy link
Collaborator

dantman commented Oct 14, 2017

Thanks for your work @fschai89

However the code has changed a fair bit and this PR actually has some issues, namely unused imports presumably leftover from earlier drafts of your code being added and no handling for older versions of Android (EXTRA_MIME_TYPES was added in API level 19, react-native supports all the way back to API level 18).

So I went ahead and just wrote a fix myself with fallbacks: 73e2d0a

@bhatti-waqas
Copy link

@dantman what is the proper solution for this issue ?

@dantman
Copy link
Collaborator

dantman commented Jul 23, 2018

@bhatti-waqas Use v3

@dantman dantman mentioned this pull request Aug 2, 2018
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.

None yet

5 participants