I am getting below error:
not an error (code 0): Could not open the database in read/write mode.
I have added
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
I am trying to enter data in the database that is present in the SD card, I am able to read the data that is already present in the database through "OPEN_READONLY". I am getting error when using "OPEN_READWRITE"
Your question is not that clear, but I'll try to answer.
Most likely, your database either:
For #2, instead of using SQLiteOpenHelper#getReadableDatabase()
, use SQLiteOpenHelper#getWritableDatabase
If your database is on an external storage unit, you have a few other things to check:
The problem might be on any of those topics.
To check if it's mounted as read-only, try the following:
/* Checks if external storage is available for read and write */
public boolean isExternalStorageWritable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
return false;
}
/* Checks if external storage is available to at least read */
public boolean isExternalStorageReadable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state) ||
Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
return true;
}
return false;
}
Taken from here.
For more info on the Environment
class, please refer to the docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With