diff --git a/packages/app/android/src/reactnative/java/io/invertase/firebase/utils/ReactNativeFirebaseUtilsModule.java b/packages/app/android/src/reactnative/java/io/invertase/firebase/utils/ReactNativeFirebaseUtilsModule.java index 7af6e49531..66b08334a8 100644 --- a/packages/app/android/src/reactnative/java/io/invertase/firebase/utils/ReactNativeFirebaseUtilsModule.java +++ b/packages/app/android/src/reactnative/java/io/invertase/firebase/utils/ReactNativeFirebaseUtilsModule.java @@ -161,10 +161,18 @@ public Map getConstants() { File externalDirectory = context.getExternalFilesDir(null); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - if ( externalDirectory != null ) { + if (externalDirectory != null) { constants.put(KEY_DOCUMENT_DIRECTORY, externalDirectory.getAbsolutePath()); + } else { + // The external directory may be null if it is truly external *and* + // the device's external storage environment changes. We will use the regular + // Files directory as a backup and note in the documentation that the directory may + // vary under rare conditions + constants.put(KEY_DOCUMENT_DIRECTORY, context.getFilesDir().getAbsolutePath()); } - } else { + } + + if (!constants.containsKey(KEY_DOCUMENT_DIRECTORY)) { constants.put(KEY_DOCUMENT_DIRECTORY, context.getFilesDir().getAbsolutePath()); } diff --git a/packages/app/lib/index.d.ts b/packages/app/lib/index.d.ts index 68c2b5c1b4..e19ebc345c 100644 --- a/packages/app/lib/index.d.ts +++ b/packages/app/lib/index.d.ts @@ -284,6 +284,11 @@ export namespace Utils { * * Use this directory to place documents that have been created by the user. * + * Normally this is the external files directory on Android but if no external storage directory found, + * e.g. removable media has been ejected by the user, it will fall back to internal storage. This may + * under rare circumstances where device storage environment changes cause the directory to be different + * between runs of the application + * * ```js * firebase.utils.FilePath.DOCUMENT_DIRECTORY; * ```