I have tried many example and did not find any good solution.
I want to store the data of my app to store in sqlite database then sync it with the google drive account of the user who installed the app.
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.
I also have applied the following example but did not succeed. https://github.com/seanpjanson/GDAADemo Create / Edit / Retrieve DB file with GDAA (Google Drive Api for Android) Unpredictable result of DriveId.getResourceId() in Google Drive Android API https://github.com/googledrive/android-quickstart
Thanks
My answer assumes that you have a keystore file to sign your app with. If you don't, this link shows you how.
The next thing you need to do is to download the Android and Google play Services SDKs and get an Android certificate, as described here
Now your app should be able to access the Google Drive APIs.
In your activity, create these variables
When the user starts the backup process call the function
singIn()
The
singIn()
function will handle a user sign - in by starting Google Sign in Client. You will need to handle the result of this client. Use the following code.After sign-in has been successfully completed, the drive client is initialised above by calling the
initializeDriveClient(GoogleSignInAccount signInAccount)
function.After the drive client is set up,
onDriveClientReady()
is called. This function proceeds to create / restore your back-up. The functionality here is very simple a. Get the base folder of the user's Google Drive account. b. Check if a back-up file exists. c. If yes, copy that backup to the local database file (over write complete file). d. If no, copy the local database file to the user's Google Drive base folder. You can add some finesse to this logic if you wish. My code is to help you understand the process.The
getRootFolder()
function proceeds as followsThere is also a function in here called
listFilesInBaseFolder()
to delete (permanently delete not simply trash) all files you created. It has been commented out in. Use it in case you want to delete files you created, use with caution. As far as I can tell it works only on files that were created by your application.Check for backup.
restoreBackUp(DriveFile driveFile)
will over write the local database file with the file found on Goole Drive.And lastly,
backUpDatabase()
creates a backup of your local database.And that is it! This should get you started with basic operations. I recommend going through Google's Developer Guide for a deeper dive.
first create a db backup in SD-card using below line
Driver_utils.create_backup(SettingActivity.this);
**add below dependencies in build.gradle **
**And for Restore use this **
**Make a static Driver_utils class **
And You Need Decomposer file just create and Copy this