lucasferreira / react-native-send-intent

React Native Android module to use Android's Intent actions for send text to shareable apps or make phone calls or opening third party apps
418 stars 159 forks source link

Update openFileChooser to work on apps with requestLegacyExternalStorage disabled #141

Closed benlondon closed 2 years ago

benlondon commented 3 years ago

Android apps targeting Android 11 (API level 30) can no longer use the requestLegacyExternalStorage attribute. This impacts apps that want to open a file chooser with a fileUrl directed at a file within the app's own storage. Explicit permission needs to be granted to the Action View Intent through the Intent.FLAG_GRANT_READ_URI_PERMISSION flag.

This article gives a good explanation on this flag and how it should be used.

The code below would not work for an app with requestLegacyExternalStorage disabled prior to this PR.

SendIntentAndroid.openFileChooser(
      {
        fileUrl: '/storage/emulated/0/Android/data/com.example.app/files/Download/example.pdf',
        type: 'application/pdf'
      },
      'Open File with:',
    );
lucasferreira commented 2 years ago

Thanks @benlondon ;)