Skip to content Skip to sidebar Skip to footer

Android: Uploaded File In App Folder Not Found After App Reinstall

I have implemented Google Drive backup in my app. I upload the backup in the App Folder. But after I reinstall my app, it is not able to find the newly created file. I there any wo

Solution 1:

Uninstalling your application will remove data in App Folder as well. This is from the REST API documentation, but I'm guessing the same thing happens on Android and other client APIs as well.

Solution 2:

I did the following:

  1. I use requestSync(GoogleApiClient)
  2. Then, in its callback, I query the contents of the drive using Drive.DriveApi.query(GoogleApiClient, query)
  3. Then, in its callback, if found, retrieve the file.
  4. Job done!

The snippet is given below for those interested.

@OverridepublicvoidonConnected(Bundle connectionHint) {
    super.onConnected(connectionHint);
    Drive.DriveApi.requestSync(getGoogleApiClient()).setResultCallback(syncCallback);
}

finalprivate ResultCallback<Status> syncCallback = newResultCallback<Status>() {
    @OverridepublicvoidonResult(@NonNull Status status) {
        if (!status.isSuccess()) {
            showMessage("Problem while retrieving results");
            return;
        }
        query = newQuery.Builder()
                .addFilter(Filters.and(Filters.eq(SearchableField.TITLE, "title"),
                        Filters.eq(SearchableField.TRASHED, false)))
                .build();
        Drive.DriveApi.query(getGoogleApiClient(), query)
                .setResultCallback(metadataCallback);
    }
};

finalprivate ResultCallback<DriveApi.MetadataBufferResult> metadataCallback =
        newResultCallback<DriveApi.MetadataBufferResult>() {
    @SuppressLint("SetTextI18n")@OverridepublicvoidonResult(@NonNull DriveApi.MetadataBufferResult result) {
        if (!result.getStatus().isSuccess()) {
            showMessage("Problem while retrieving results");
            return;
        }

        MetadataBuffermdb= result.getMetadataBuffer();
        for (Metadata md : mdb) {
            DatecreatedDate= md.getCreatedDate();
            DriveIddriveId= md.getDriveId();
        }

        readFromDrive(driveId);
    }
};

Thanks for all your help!

Post a Comment for "Android: Uploaded File In App Folder Not Found After App Reinstall"