I am trying to include functionality for backing up and restoring an application database in the Google applications folder for drives (not visible to the user). I reviewed the basic setup guide the setup guide given for android and can make the user authorize the application and go to the point where the onConnected method is called.
The problem I encountered is that I'm not sure how to go about βsendingβ the database file (.db) from the device to the Google Drive application folder. Google provided a common snippet for creating a new file, but more on that. I found a previously asked question, vaguely similar to what I'm looking for a Google drive to backup and restore the database and general settings of the Android application , but again not what I'm looking for.
A google search does not return useful links, perhaps because it is a relatively new api.
UPDATE 1:
Sharing onConnected () code,
public void onConnected(Bundle bundle) { Toast.makeText(GoogleSignIn.this, "In onConnected activity", Toast.LENGTH_SHORT).show(); // Testing to see if database is indeed uploaded to google drive app folder String db_name = "XXX_DB"; String currentDBPath = "/data/" + "com.abc.efg" + "/databases/" + db_name; saveToDrive( Drive.DriveApi.getAppFolder(mGoogleApiClientDrive), "XXX_DB.db", "application/x-sqlite3", new java.io.File(currentDBPath) ); }
UPDATE 2:
The solution below works fine for loading the database into the Google Drive application folder. For those who may encounter a similar problem, try changing the database path to "/data/data/com.abc.efg/databases/" + db_name instead of "/data/com.abc.efg/databases/" + db_name
The next step is to get and restore the database from the Google Drive application folder. Must update this question if I can get it to work.
android android-sqlite google-drive-android-api
Paritosh
source share