diff --git a/android/src/main/java/com/op/sqlite/OPSQLiteModule.kt b/android/src/main/java/com/op/sqlite/OPSQLiteModule.kt index 688832fa..49a01b9f 100644 --- a/android/src/main/java/com/op/sqlite/OPSQLiteModule.kt +++ b/android/src/main/java/com/op/sqlite/OPSQLiteModule.kt @@ -12,14 +12,13 @@ import java.io.InputStream import java.io.OutputStream import com.facebook.react.util.RNLog; -//@ReactModule(name = OPSQLiteModule.NAME) internal class OPSQLiteModule(context: ReactApplicationContext?) : ReactContextBaseJavaModule(context) { override fun getName(): String { return NAME } - fun getTypedExportedConstants(): MutableMap { - val constants: MutableMap = HashMap() + fun getTypedExportedConstants(): MutableMap { + val constants: MutableMap = HashMap() val context = reactApplicationContext val dbPath = context.getDatabasePath("defaultDatabase") @@ -28,14 +27,14 @@ internal class OPSQLiteModule(context: ReactApplicationContext?) : ReactContextB constants["ANDROID_DATABASE_PATH"] = dbPath val filesPath = context.filesDir.absolutePath constants["ANDROID_FILES_PATH"] = filesPath - val externalFilesDir = context.getExternalFilesDir(null)!!.absolutePath - constants["ANDROID_EXTERNAL_FILES_PATH"] = externalFilesDir - constants["IOS_DOCUMENT_PATH"] = "" - constants["IOS_LIBRARY_PATH"] = "" + val externalFilesDir = context.getExternalFilesDir(null) + constants["ANDROID_EXTERNAL_FILES_PATH"] = externalFilesDir?.absolutePath + constants["IOS_DOCUMENT_PATH"] = null + constants["IOS_LIBRARY_PATH"] = null return constants } - override fun getConstants(): MutableMap? { + override fun getConstants(): MutableMap { return getTypedExportedConstants() } @@ -53,7 +52,6 @@ internal class OPSQLiteModule(context: ReactApplicationContext?) : ReactContextB @ReactMethod(isBlockingSynchronousMethod = true) fun getDylibPath(bundleId: String, name: String): Boolean { throw Exception("Do not call getDylibPath on Android") - return true } @ReactMethod diff --git a/docs/docs/configuration.md b/docs/docs/configuration.md index 33367256..ce4b65df 100644 --- a/docs/docs/configuration.md +++ b/docs/docs/configuration.md @@ -45,13 +45,15 @@ const db = open({ }); ``` -If you want to access the SD card app's directory: +If you want to access the SD card app's directory. However, `ANDROID_EXTERNAL_FILES_PATH` **can be null**, sometimes there are OS/Device level errors on which the OS does not detect the directory correctly. You should always have a fallback. ```tsx const db = open({ name: 'myDB', location: - Platform.OS === 'ios' ? IOS_LIBRARY_PATH : ANDROID_EXTERNAL_FILES_PATH, + Platform.OS === 'ios' + ? IOS_LIBRARY_PATH + : ANDROID_EXTERNAL_FILES_PATH ?? ANDROID_DATABASE_PATH, }); ``` @@ -63,7 +65,7 @@ const db = open({ location: Platform.OS === 'ios' ? IOS_LIBRARY_PATH - : `${ANDROID_EXTERNAL_FILES_PATH}/dbs/`, + : `${ANDROID_EXTERNAL_FILES_PATH}/databases/`, }); ```