I have read solution from Failed to change locale for db '/data/data/my.easymedi.controller/databases/EasyMediInfo.db' to 'en_US' but it doesnt help me. I st
The problem that you get is that the file cannot be opened. Probably its something wrong with your path (it could be slightly different between diferent android versions), and anyways, you should never hardcode it.
You can get database path with context.getDatabasePath();
you pass the desired name to the file (no matter if it exists or not). And actually you are supposed to do it that way
For that, at any place you are using something like String outFileName = DB_PATH + DB_NAME;
you should change it for
String outFileName =myContext.getDatabasePath(DB_NAME).getPath() ;
and that's the real valid location for your file. so , your copyDataBase() will be like this
private void copyDataBase() throws IOException {
// Open your local db as the input stream
InputStream myInput = context.getAssets().open("db/" + DATABASE_NAME);
// Path to the just created empty db
String outFileName =myContext.getDatabasePath(DB_NAME).getPath() ;
// Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);
// transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer)) > 0) {
myOutput.write(buffer, 0, length);
}
// Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
}
and the same change in your private boolean checkDataBase()