0

I wanted to implement a functionality where user selects an external storage directory and i read and list files in side the seleted directory. I am using react-native-document-picker library to pick the directory.

const per = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE)
const res = await DocumentPicker.pickDirectory()
const conn = await RNFS.readDir(res.uri)

i see this as the response of DocumentPicker.pickDirectory()function

{"uri": "content://com.android.externalstorage.documents/tree/primary%3ADownload%2FIRCTC%20ERS"}

but when i try to react the directory using RNFS.readDir(res.uri), I am getting below error

[Error: Folder does not exist]

i added these permissions in my AndroidManifest.xml file.


<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
 ...
 android:requestLegacyExternalStorage="true"
</application>

Ravi
  • 165
  • 3
  • 11
  • You got a SAF content scheme. So use SAF methods to list. In Java you would use DocumentFile.listFiles(). You do not need those permissions in manifest file. No need to request legacy external storage. – blackapps Apr 19 '23 at 10:19
  • But the directory i am trying to read is external directory, is it possible to do that with permissions? And when i try list the directory it is thrwing me error – Ravi Apr 19 '23 at 10:30
  • You are using the directory picker. So use the content scheme the picker gives you. – blackapps Apr 19 '23 at 10:35

0 Answers0