I am writting an app with an instant messenger function. Users would write text or share images in the IM function. The text data and file name of images are stored in the sqlite file while the images are stored in the device.
Since my server will not keep the data, the user would not get the chat record when he / she switches to a new device. With reference to whatsapp, they allow the users to back up the chat records and images to Google Drive on a regular basis and get the data back from the drive as shown in the picture below.
When I go to my own google drive, I would find "Whatsapp" is connected to my google drive as shown below.
I am new to the Google Drive API in Android and I would like to backup my sqlite database and images in the same way as Whatsapp does. I know there are few questions related to the back-up of sqlite database to Google Drive but it seems that it only contains part of the codes and this makes the beginner quite difficult to understand.
Will there be any sample projects on github, questions on stackoverflow or tutorials that would allow me learn how to back up sqlite database and images programmatically in Android step by step?
In additions, I am surprised to see only whatsapp is connected to my Google Drive but no more other apps, so I don't know if third-party developers would have the same access to Google Drive and complete the backup in the same way as Whatsapp.
1. copy your db to sdcard 2. if reinstall, copy db back to the app. @earthw0rmjim Any approach in which I can get the original state retained without the network.
There is also a button which will show the data from google drive and user can edit and update the data so the updated data is then store in the google drive. I'm new in Android development please help me. you can compress your database file in ZIP and send that zip to server. then send that .
You can back up your app data, call history, and other info to your Google Drive. You get unlimited backup for “full resolution” photos and videos (limited backup for original resolution). Once you've backed up your app history, etc.
Have you seen https://github.com/googledrive/android-demos? I think you need to follow "Create a file in App Folder" to save your sqlite file in the user's hidden AppData folder. To retrieve the file back you could query the AppData folder (make sure to call requestSync() before querying to ensure the cache is up-to-date).
This is certainly doable. You will need to learn how to upload files to Google Drive programmatically.
Will there be any sample projects on github, questions on stackoverflow or tutorials that would allow me learn how to back up sqlite database and images programmatically in Android step by step?
There are several samples like:
Tutorials: Try this Java Quickstart for uploading to Drive since you're going to do it in Android.
An example of saving files to Google Drive SDK in Android.
Github samples for Android and Drive SDK.
For uploading images, note that you will be using an image mimetype like image/png for .png and image/jpeg for .jpg files. For uploading sql database to Drive, here's a snippet from this sample.
String mimeType = MimeTypeMap.getSingleton().getExtensionFromMimeType("db");
MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle(GOOGLE_DRIVE_FILE_NAME) // Google Drive File name
.setMimeType(mimeType)
.setStarred(true).build();
// create a file on root folder
Drive.DriveApi.getRootFolder(api)
.createFile(api, changeSet, result.getDriveContents())
.setResultCallback(backupFileCallback);
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