Zubin Kadva
Zubin Kadva

Reputation: 601

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 workaround for this?

Thanks.

Upvotes: 0

Views: 364

Answers (2)

Zubin Kadva
Zubin Kadva

Reputation: 601

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.

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

final private ResultCallback<Status> syncCallback = new ResultCallback<Status>() {
    @Override
    public void onResult(@NonNull Status status) {
        if (!status.isSuccess()) {
            showMessage("Problem while retrieving results");
            return;
        }
        query = new Query.Builder()
                .addFilter(Filters.and(Filters.eq(SearchableField.TITLE, "title"),
                        Filters.eq(SearchableField.TRASHED, false)))
                .build();
        Drive.DriveApi.query(getGoogleApiClient(), query)
                .setResultCallback(metadataCallback);
    }
};

final private ResultCallback<DriveApi.MetadataBufferResult> metadataCallback =
        new ResultCallback<DriveApi.MetadataBufferResult>() {
    @SuppressLint("SetTextI18n")
    @Override
    public void onResult(@NonNull DriveApi.MetadataBufferResult result) {
        if (!result.getStatus().isSuccess()) {
            showMessage("Problem while retrieving results");
            return;
        }

        MetadataBuffer mdb = result.getMetadataBuffer();
        for (Metadata md : mdb) {
            Date createdDate = md.getCreatedDate();
            DriveId driveId = md.getDriveId();
        }

        readFromDrive(driveId);
    }
};

Thanks for all your help!

Upvotes: 1

adjuremods
adjuremods

Reputation: 2998

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.

Upvotes: 1

Related Questions