Reputation: 3162
In my android app user can insert data and when he/she click the save button that inserted data will be saved in sqlite database. I have a predefined database which is in the assets folder (.db file). Now it can save data and I can see that inserted data in eclipse using sqlite manage plugin. But the problem is it cannot update the database in the assets folder. How can I solve this problem ? Can anyone please be so kind enough to explain what should i do ?
Best regards
Thanx in advance
Upvotes: 0
Views: 2554
Reputation: 3193
You can not do any operations on database which you have kept in assets because its just the schema on runtime the database gets copies in data/data/pkg_name/database/myDb.db and changes would be reflected over there not in assets.
Upvotes: 2
Reputation: 12181
What I want to know is how could I update the database which is in the assets folder after I inserting data.
Editing the Assets folder in runtime is not possible. source.
This Loads the database from the asset folder:
// Copies DB from assests
private void copyDataBase() throws IOException {
InputStream mInput = mContext.getAssets().open(DB_NAME);
String outFileName = DB_PATH + DB_NAME;
OutputStream mOutput = new FileOutputStream(outFileName);
byte[] mBuffer = new byte[1024];
int mLength;
while ((mLength = mInput.read(mBuffer)) > 0) {
mOutput.write(mBuffer, 0, mLength);
}
mOutput.flush();
mOutput.close();
mInput.close();
}
See this answer for updating your db from assets.
Upvotes: 3