アプリとそのデータベースを更新することにしましたが、以下のコードを実行してアプリを実行すると、データベースが奇妙な方法でコピーされます。一部の部分はコピーされ、一部はコピーされません。
私を最も混乱させているのは、Nexusで問題が発生している間、すべてがエミュレーターで完全に機能することです。
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
try {
copyDatabase();
} catch (IOException e) {
throw new Error("Error copying database" + e.toString());
}
}
public void copyDatabase() throws IOException {
// Open your local db as the input stream
InputStream myinput = myContext.getAssets().open(DB_NAME);
// Path to the just created empty db
String outfilename = DB_PATH + DB_NAME;
// Open the empty db as the output stream
OutputStream myoutput = new FileOutputStream(outfilename);
// transfer byte to inputfile to 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();
}