shanti
shanti

Reputation: 367

Google Drive App Folder backup data getting lost on app uninstall

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.

Upvotes: 3

Views: 1699

Answers (3)

Vasudevan Nair R
Vasudevan Nair R

Reputation: 203

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...

Upvotes: 0

alstr
alstr

Reputation: 1556

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
    }
});

Upvotes: 1

shanti
shanti

Reputation: 367

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

Upvotes: 3

Related Questions