I am getting below error:
not an error (code 0): Could not open the database in read/write mode.
I have added
With version 4.4 KitKat some changes were introduced related to how Android handles storage and data security.
For example even if isExternalStorageReadable() will return true you will not be able to write to External SD Card but only to the directory returned by Environment.getExternalStorageDirectory().
/* 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;
}
To be able to delete, write, move files you have to use the Storage Access Framework which lets you access files located on your phone but also any remote files like for example files in Google Drive.
To open a database you have to provide a path but the Document Provider Api only lets you open an Input Stream or move files so in order to open a database you will have to move/copy the file to some Private Internal storage or to Environment.getExternalStorageDirectory() directory.
More info on this topic:
https://developer.android.com/guide/topics/providers/document-provider.html
https://stackoverflow.com/a/43317703/1502079
https://stackoverflow.com/a/21674485/1502079