Google drive to back up and restore database and shared preferences of Android application

前端 未结 2 1409
再見小時候
再見小時候 2020-12-13 05:19

I need to create a backup of my application which would include creating a backup of 2 databases and also the shared preferences using Google drive API. I was able to get th

2条回答
  •  醉话见心
    2020-12-13 05:51

    Turns out the only issue was creating the file before actualy adding data to it. Called the constructor of my dbhelper before writing to the db file.

    used the following code:

    java.io.File dir = myContext.getDatabasePath("myDb.db");
    mOutput = new FileOutputStream(outFileName);
            byte[] mBuffer = new byte[1024];
            int mLength;
            while ((mLength = mInput.read(mBuffer)) > 0) {
                mOutput.write(mBuffer, 0, mLength);
            }
            mOutput.flush();
    

    Thanks for taking the effort to help guys !

    I will definitely take a look at your SQLiteExample @seanpj. Will get back if i find it as a better solution.

提交回复
热议问题