java - How to delete a file on google drive using Google Drive Android API -


i'm new google drive android api, , i'm learning it. encountered problem cannot delete file using google drive android api, there isn't example of it. can anybood me question? alot.

update (april 2015)
gdaa has it's own 'trash' functionality rendering answer below irrelevant.

original answer:
cheryl mentioned above, can combine these 2 apis.

the following code snippet, taken here, shows how can done:

first, gain access both googleapiclient, , ...services.drive.drive

googleapiclient _gac; com.google.api.services.drive.drive _drvsvc;  public void init(mainactivity ctx, string email){   // build gdaa  googleapiclient   _gac = new googleapiclient.builder(ctx).addapi(com.google.android.gms.drive.drive.api)         .addscope(com.google.android.gms.drive.drive.scope_file).setaccountname(email)         .addconnectioncallbacks(ctx).addonconnectionfailedlistener(ctx).build();    // build restful (drivesdkv2) service fall delete   com.google.api.client.googleapis.extensions.android.gms.auth.googleaccountcredential crd =   googleaccountcredential     .usingoauth2(ctx, arrays.aslist(com.google.api.services.drive.drivescopes.drive_file));   crd.setselectedaccountname(email);   _drvsvc = new com.google.api.services.drive.drive.builder(           androidhttp.newcompatibletransport(), new gsonfactory(), crd).build(); } 

second, implement restful api calls on gdaa's driveid:

public void trash(driveid did) {   try {     string fileid =  did.getresourceid();       if (fileid != null)         _drvsvc.files().trash(fileid).execute();   } catch (exception e) {}  }  public void delete(driveid did) {   try {     string fileid = did.getresourceid();       if (fileid != null)         _drvsvc.files().delete(fileid).execute();   } catch (exception e) {}  } 

... , voila, deleting files. , usual, not without problems.

first, if try delete file after created it, getresourceid() falls on it's face, returning null. not related issue here, i'm gonna raise nag on it.

and second, it hack! , should not stay in code past gdaa implementation of trash , delete functionality.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -