I donβt know if it is still useful, but here is a solution for others who get here to see the Einser. The code you used works for most phones, some older phones have different behavior with the getReadableDatabase () function. Therefore, your problem is not in the copyDataBase function, but in the createDataBase function.
in createDataBase () the following check exists:
this.getReadableDatabase();
This checks if there is already a database with the specified name and if an empty database is not created so that it can be overwritten using the one in the resource folder. On new devices, this works flawlessly, but there are some devices on which it does not work. Mostly old devices. I donβt know exactly why, but it seems that the getReadableDatabase () function not only gets the database, but also opens it. If you then copy the database from the assets folder on top of it, it still has a pointer to an empty database, and you will get a table that does not contain errors.
So, for it to work on all devices, you must change it to the following lines:
SQLiteDatabase db = this.getReadableDatabase(); if (db.isOpen()){ db.close(); }
Even if the database is open on the check, it closes after that, and this will not give you more problems.
Tom groentjes
source share