Trash, Delete in new Google Drive Android API?

后端 未结 7 675
余生分开走
余生分开走 2020-11-29 11:54

UPDATE (May 2015):
the \'trash\' functionality has been implemented in GDAA, making the question below irrelevant.

ORIGINAL QUESTION:

7条回答
  •  离开以前
    2020-11-29 12:07

    While Google Drive Android API does not yet support delete, you can delete the contents (and, at the same time, rename the title, so that you can ignore it in future). This might be useful to devs using the AppFolder.

    private void deleteContents(final DriveFile driveFile) {
      driveFile.open(mGoogleApiClient, DriveFile.MODE_WRITE_ONLY, null).setResultCallback(new ResultCallback() {
        @Override
        public void onResult(DriveContentsResult result) {
          if (!result.getStatus().isSuccess()) {
            // oh noes!
            return;
          }
          DriveContents contents = result.getDriveContents();
          try {
            MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder().setTitle(DELETED_DRIVE_TITLE).build();
            contents.commit(mGoogleApiClient, metadataChangeSet).setResultCallback(
                    new ResultCallback() {
                      @Override
                      public void onResult(Status status) {
                        if (!status.isSuccess()) {
                          // more oh noes!
                          return;
                        }
                        // nicely deleted
                      }
                    });
          }
          catch (Exception e) {
            contents.discard(mGoogleApiClient);
          }
        }
      });
    }
    

提交回复
热议问题