Im doing an app which uses sqlite database There is an feature in my app having a button 'Update Database'.
When user clicks on the 'Update Database' button i need to upgrade the old db file with new db file from URL.
How to do this. the research tells me that we cant change a db as it gets place in an .apk file. Is there any solution to this. Please help me out. Thank you.
private void importDatabase(String inputFileName) throws IOException
{
InputStream mInput = new FileInputStream(inputFileName);
String outFileName = YOUR_DB_PATH_HERE;
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();
}
EDIT:
You may find it helpfull:
How to use an existing database with an Android application
Simply you could download the db file from URL using Download Manager and copy the file to this path
/data/data/<YOUR PACKAGE NAME>/databases/
It will automatically update.I have used this and is working
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With