I have implemented database backup and restore to Google Drive App folder using Google Drive Android API. I tested it and it was working fine, which means I could create my db file in the hidden app folder in Google Drive, and on uninstalling and reinstalling the app, I could use the restore functionality of my app to restore the database.
But recently, it has stopped working. Now, when I take back up and uninstall my app and try to restore it from Google Drive's app folder, it fails to find my backup file. Has Google or Android changed anything recently?
I have done all my testing on Android 6.0.1, Nexus 5. I know starting 6.0, Google has introduced Auto Backup. But does it also delete anything previously stored in App folder? It was working on 6.0.1 till 2-3 days back. The google-play-services version of my Nexus 5 is 10.2.98. Please help.
Asked
Active
Viewed 1,597 times
3

shanti
- 359
- 5
- 20
-
Your app folder data should not be touched. You should be able to go to the Drive on the web to see how much space your app is taking up in drive. (Settings->Manage Apps). Are you sure that your backup is making it to the appData folder? That upload occurs asynchronously and may just be slower that it was. A quick search shows that Google has introduced this sort of problem before: [Android Google drive App data folder return empty when I use queryChildren](http://stackoverflow.com/questions/23840846/android-google-drive-app-data-folder-return-empty-when-i-use-querychildren). – Cheticamp Mar 01 '17 at 13:46
-
Yes, my backup file remains there as long as I don't uninstall the app. Before uninstalling, I can successfully restore it from app folder. But after uninstalling, the metadata buffer returns empty for that filename. I have gone through the link that you have mentioned. I feel it's a Google play services bug that has recurred somehow. But, I need a solution as my app needs it. – shanti Mar 01 '17 at 16:02
-
After uninstalling, can you see that storage is still consumed in the app data folder through the web interface? I would temporarily change the scope away from appDataFolder so I could more easily see what is happening. – Cheticamp Mar 01 '17 at 16:09
-
It would make sense to locally delete app data files when the only app that can access them is deleted, although I would not expect the server to delete them. How are you trying to read the file that is missing? Could this be a timing issue if GDAA needs to go to the server to reload the file? – Cheticamp Mar 01 '17 at 16:20
-
Yes, after backup "hidden app data folder" in Manage Apps in web google drive shows 1 MB. After uninstall, it still shows 1 MB, but on trying to restore it using Google Drive Android API returns meta data buffer of my query returns empty. I followed this link to take back up: http://stackoverflow.com/questions/33602812/backup-restore-sqllite-database-to-google-drive-app-folder?noredirect=1&lq=1 and followed @seanpj – shanti Mar 02 '17 at 05:13
3 Answers
3
I solved this issue by using Drive.DriveApi.requestSync() method in onConnected() method like this:
@Override
public void onConnected(Bundle connectionHint) {
Drive.DriveApi.requestSync(mGoogleApiClient).setResultCallback(syncCallBack);
}
Drive.DriveApi.requestSync(mGoogleApiClient).setResultCallback(syncCallBack);
private ResultCallback<Status> syncCallBack = new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (!status.isSuccess()) {
if (DriveStatusCodes.DRIVE_RATE_LIMIT_EXCEEDED == status.getStatusCode()) {
//intimate user to wait for some time if you want to
}
}
//now query db file from google drive's app folder
}
};
This link gave me the pointer:
Android Google Drive App data folder not listing all childrens
-
1Watch out for `DRIVE_RATE_LIMIT_EXCEEDED`. Google has really cranked down on how frequently`requestSync` can be called. – Cheticamp Mar 02 '17 at 12:18
1
For those who are still experiencing this problem and using the latest Drive API for Android, the solution marked above is deprecated. This worked for me after much, much searching:
DriveClient driveClient = Drive.getDriveClient(MainActivity.this, googleSignInAccount);
driveClient.requestSync().addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
// Do stuff here
}
});

alstr
- 1,358
- 18
- 34
0
Above mentioned approaches will fix the issue of not finding the files from App folder once you reinstalled the App.
For the newer Google Drive API, we should retrieve the DriveClient and then do the requestSync()
DriveClient mDriveClient = Drive.getDriveClient(getApplicationContext(),
mGoogleSignInAccount);
mDriveClient.requestSync().addOnSuccessListener(aVoid -> {
// your codes to query the file goes here
}
Happy Androiding...

Vasudevan Nair R
- 183
- 1
- 3
- 12