Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open file downloaded within React-Native app with another app

Tags:

react-native

I am trying to open files (images, pdfs, videos, etc) downloaded with my React-Native app from my server.

So I'm using RNFetchBlob to download the file then I'm doing the following depending if it's an iOS or Android device:

openFile = (item, path) => {
    if (Platform.OS === 'ios') {
      RNFetchBlob.ios.previewDocument(path)
    } else {
      // I've tried setting a real mimetype instead of / but it still doesn't work
      RNFetchBlob.android.actionViewIntent(path, '/')
    }
}

On iOS it works as expected but nothing happens on Android even though I have apps that can read images, pdfs or videos on the device I'm testing on.

Any ideas why this doesn't work or how I could make the same thing with another library ?

like image 890
Moumou Avatar asked Nov 01 '25 16:11

Moumou


1 Answers

NOTE:

The PR has been merged back in 09/2019 so it should work properly and the answer below should be ignored.


Found out the reason for this, it's a know bug of the library and has a PR waiting to be merged (no timeframe from the repo owner). Here is the link to the PR: https://github.com/joltup/rn-fetch-blob/pull/317

So basically this needs to be added to line 122-123 of file android/src/main/java/com/RNFetchBlob/RNFetchBlob.java:

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

If above is not working do to the below step: overwrite the 121 line in android/src/main/java/com/RNFetchBlob/RNFetchBlob.java:

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // 121 line
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // 122 line
like image 113
Moumou Avatar answered Nov 03 '25 13:11

Moumou