React Native Android module to use Android's Storage Access Framework and DocumentsProvier to access files on the device.
yarn add react-native-android-fs
- Link automatically with (if your version of react-native doesn't support autolinking):
react-native link react-native-android-fs
import AndroidFs from 'react-native-android-fs'
// pick directory and read content
AndroidFs.openDirectoryPicker(async (treeUri) => {
const contentArray = await AndroidFs.readDir(treeUri)
for (let i=0; i<contentArray.length; i++) {
console.log(contentArray[i])
/*
{
'name' : <string>,
'path' : <string>,
'lastModified' : <number>,
'isDirectory' : <boolean>,
'isFile' : <boolean>
}
*/
}
})
// create new directory
const newPath = await AndroidFs.mkdir(path, name)
// create new file
const newPath = await AndroidFs.touch(path, filename, mimeType)
// write text file
await AndroidFs.writeTextFile(fileUri, text)
// read file content
const contentString = await AndroidFs.readTextFile(fileUri)
// delete file
await AndroidFs.delete(fileUri)
MIT