0

First error come when I'm trying to get Resource id from Driveid.

DriveFile dfile= Drive.DriveApi.getFile(mGoogleApiClient,DriveId.decodeFromString(driveId));                                            
Log.e(TAG,"Driveid>>>>" + driveId);                                             
String resourceID= dfile.getDriveId().getResourceId().toString();

Whenever I got Resource id and trying to delete item from google drive.

com.google.api.services.drive.Drive service;

service.files().delete(resourceID).execute();

Here Logcat ERROR:

enter image description here

Please Give me standard Solution for delete file from google drive.

seanpj
  • 6,735
  • 2
  • 33
  • 54
Devganiya Hitesh
  • 1,207
  • 2
  • 17
  • 31

2 Answers2

2

For newly created files, the resourceId will not be populated right away. It will be populated once the file is committed to the server. You should check if it is null before using it.

Cheryl Simon
  • 46,552
  • 15
  • 93
  • 82
0

For 'trash', there is no need to mix the GDAA with the REST Api anymore. Since GooPlaySvcs release 7.0 (March 2015), there is a 'trash()' method in the GDAA that does not require the ResourceId, shielding you from the timing issues related to the the latency/existence of it.

For short demonstration, here is a 'trash' wrapper for the GDAA that does not need ResourceId. On top of it, you don't need to worry about the network (wifi) on-line / off-line state.

private static GoogleApiClient mGAC;
...  
static void trash(DriveId dId) {
  if (mGAC != null && mGAC.isConnected() && dId != null) {
    DriveResource driveResource;
    if (dId.getResourceType() == DriveId.RESOURCE_TYPE_FOLDER) {
      driveResource = Drive.DriveApi.getFolder(mGAC, dId);
    } else {
      driveResource = Drive.DriveApi.getFile(mGAC, dId);
    }
    if (driveResource != null) {
      driveResource.trash(mGAC).setResultCallback(new ResultCallback<Status>() {
        @Override
        public void onResult(Status status) {
          // bingo, trashed successfully !!!   
        }
      });
    }
  }
}

Good Luck

Community
  • 1
  • 1
seanpj
  • 6,735
  • 2
  • 33
  • 54