Is there a way to open a SQLiteDatabase file from the SD card with OPEN_READWRITE access? This is for external database files provided by a user, not internal application data. (Edit: Handling Uri's to get the actual file paths but hard coded for a simplified example)
The following works using a path to internal phone storage, external to app:
SQLiteDatabase sqlite = SQLiteDatabase.openDatabase(
"/storage/emulated/0/test.db",
null,
SQLiteDatabase.OPEN_READWRITE | SQLiteDatabase.NO_LOCALIZED_COLLATORS);
Using a path to the SD card however throws an exception:
SQLiteDatabase sqlite = SQLiteDatabase.openDatabase(
"/storage/extSdCard/test.db",
null,
SQLiteDatabase.OPEN_READWRITE | SQLiteDatabase.NO_LOCALIZED_COLLATORS);
Exception:
android.database.sqlite.SQLiteException: not an error (code 0): Could not open the database in read/write mode.
But opening with OPEN_READONLY works fine:
SQLiteDatabase sqlite = SQLiteDatabase.openDatabase(
"/storage/extSdCard/test.db",
null,
SQLiteDatabase.OPEN_READONLY | SQLiteDatabase.NO_LOCALIZED_COLLATORS);
External storage permissions in the manifest:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Was hoping the Storage Access Framework or Lollipop SD API could help but am not having any luck.
Is there any way to open a SQLiteDatabase file with write access from the SD card?