I am writing a simple app using react native to make some file operations done automatically. I have tried packages like strong text react-native-fs, but I found that there are some files/folders that can not be read using
RNFS.ls(PATH).
Trying to list files in that folder will throw an exception.
However, these files can be displayed using ls command in adb shell. So I am wondering if there is a way that we can run shell commands in react native like we make some system calls in java/python?
Thanks
You can easily run a shell command from Java and call it from React Native using React Native's Native Modules. You can find more information here:
https://facebook.github.io/react-native/docs/0.60/native-modules-android#callbacks
And for your Java command, you'd want to use something like this:
String command = "ls " + path; // Where path is your desired path.
Runtime runtime = Runtime.getRuntime();
Process result = runtime.exec( command );
BufferedReader bufferedReader = new BufferedReader( new InputStreamReader( result.getInputStream() ) );
String[] parts = bufferedReader.readLine().split( "\\s+" );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With