Try to load data from a local db file (preferably in SD Card).
I first check if sd-card is mounted before performing any operation.
if (isExternalStorageWritable()) {
loadFile(SharedPref.getDBPath(this), new DataLoaderCallback() {
@Override
public void onDataRetrieved(ImportModel importModel) {
}
});
}
this basically calls this part of the code that crashses the app.
private SQLiteDatabase connect() {
String dbPath = SharedPref.getManifestPath(mContext);
File dbfile = new File(dbPath);
if (dbfile.exists()) {
return SQLiteDatabase.openDatabase(dbfile.getAbsolutePath(), null, SQLiteDatabase.OPEN_READWRITE);
}
return null;
}
and this is the error :
Failed to open database '/storage/sdcard1/Alarms/data/manifest'.
android.database.sqlite.SQLiteException: not an error (code 0): Could not open the database in read/write mode.
at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:212)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:196)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:806)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:791)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:669)
When I use:
return SQLiteDatabase.openDatabase(dbfile.getAbsolutePath(), null, SQLiteDatabase.OPEN_READONLY);
It does work but I can only read from the file. I want to read and write. Hence, OPEN_READWRITE
.
The file has read and write permission , and I have this permissions added in manifest.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
How do I fix this ?