diff --git a/FS.common.js b/FS.common.js index 31f6d11..074cdf4 100644 --- a/FS.common.js +++ b/FS.common.js @@ -189,6 +189,7 @@ var RNFS = { MainBundlePath: RNFSManager.MainBundlePath, CachesDirectoryPath: RNFSManager.NSCachesDirectoryPath, DocumentDirectoryPath: RNFSManager.NSDocumentDirectoryPath, + ExternalDirectoryPath: RNFSManager.NSExternalDirectoryPath, LibraryDirectoryPath: RNFSManager.NSLibraryDirectoryPath, PicturesDirectoryPath: RNFSManager.NSPicturesDirectoryPath }; diff --git a/README.md b/README.md index a1811c2..0d10b41 100644 --- a/README.md +++ b/README.md @@ -171,6 +171,7 @@ The following constants are available on the `RNFS` export: `MainBundlePath` (`String`) The absolute path to the main bundle directory `CachesDirectoryPath` (`String`) The absolute path to the caches directory `DocumentDirectoryPath` (`String`) The absolute path to the document directory +`ExternalDirectoryPath` (`String`) The absolute path to the external, shared directory (android only) ### `promise readDir(path)` diff --git a/RNFSManager.m b/RNFSManager.m index 4fe5b06..ca8cfcb 100644 --- a/RNFSManager.m +++ b/RNFSManager.m @@ -279,6 +279,7 @@ RCT_EXPORT_METHOD(pathForBundle:(NSString *)bundleNamed @"MainBundlePath": [[NSBundle mainBundle] bundlePath], @"NSCachesDirectoryPath": [self getPathForDirectory:NSCachesDirectory], @"NSDocumentDirectoryPath": [self getPathForDirectory:NSDocumentDirectory], + @"NSExternalDirectoryPath": [NSNull null], @"NSLibraryDirectoryPath": [self getPathForDirectory:NSLibraryDirectory], @"NSFileTypeRegular": NSFileTypeRegular, @"NSFileTypeDirectory": NSFileTypeDirectory diff --git a/android/src/main/java/com/rnfs/RNFSManager.java b/android/src/main/java/com/rnfs/RNFSManager.java index dd3ea64..aeca38e 100644 --- a/android/src/main/java/com/rnfs/RNFSManager.java +++ b/android/src/main/java/com/rnfs/RNFSManager.java @@ -38,6 +38,7 @@ import com.facebook.react.modules.core.DeviceEventManagerModule; public class RNFSManager extends ReactContextBaseJavaModule { private static final String NSDocumentDirectoryPath = "NSDocumentDirectoryPath"; + private static final String NSExternalDirectoryPath = "NSExternalDirectoryPath"; private static final String NSPicturesDirectoryPath = "NSPicturesDirectoryPath"; private static final String NSCachesDirectoryPath = "NSCachesDirectoryPath"; private static final String NSDocumentDirectory = "NSDocumentDirectory"; @@ -310,6 +311,12 @@ public class RNFSManager extends ReactContextBaseJavaModule { final Map constants = new HashMap<>(); constants.put(NSDocumentDirectory, 0); constants.put(NSDocumentDirectoryPath, this.getReactApplicationContext().getFilesDir().getAbsolutePath()); + File externalDirectory = this.getReactApplicationContext().getExternalFilesDir(null); + if (externalDirectory != null) { + constants.put(NSExternalDirectoryPath, externalDirectory.getAbsolutePath()); + } else { + constants.put(NSExternalDirectoryPath, null); + } constants.put(NSPicturesDirectoryPath, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath()); constants.put(NSCachesDirectoryPath, this.getReactApplicationContext().getCacheDir().getAbsolutePath()); constants.put(NSFileTypeRegular, 0);