joltup / rn-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.81k stars 772 forks source link

[Android] Fix actionViewIntent for SDK < 24 #685

Closed Chris-Guy closed 2 years ago

Chris-Guy commented 3 years ago

actionViewIntent does not work for SDK < 24

It seems that this part of the code was introduced when migrating to Android file providers: https://github.com/wkh237/react-native-fetch-blob/issues/358 The blog post about it: https://inthecheesefactory.com/blog/how-to-share-access-to-file-with-fileprovider-on-android-nougat/en says that from the moment we set targetSdkVersion to something superior to 24, we need to pass through a file provider: "This behavior will happen only when you change your app's targetSdkVersion to 24 or above".

I imagine that the dev that implemented it thinking (with good will) that he needed to separate the two flows depending on the device Android SDK version at the runtime, but now that the default config is set as 28 in the build.gradle, we should remove this logic. File providers are meant to work even for Android SDK < 24, it all depends on the target version set when we build.

Also, I take some part of the PR for [Android] Promise resolve and reject for actionViewIntent (https://github.com/joltup/rn-fetch-blob/pull/535) as it is very useful to have a promise rejection when the intent is not resolved (kudos to MikeChugunov)

bitcrumb commented 3 years ago

I stumbled upon this issue today as well. Took me a good while before realising. However, since this library is now marked as unmaintained, I wouldn't expect this to get merged :(

R4DIC4L commented 3 years ago

Someone forked this project to continue working on it: https://github.com/RonRadtke/react-native-blob-util. Maybe suggesting this fix there would help.

I have also had this problem in android and solved it by forking react-native-open-doc and adding a function openWithSuggestedMime to use OPEN_DOCUMENT instead of ACTION_VIEW. I then released a public npm package with this fix. I was also using react-native-document-picker and react-native-image-picker which already provide me the file's mime type.

bitcrumb commented 3 years ago

@R4DIC4L Thanks for such a swift response! I'll look into the alternatives. Thanks man, much appreciated :)