1

I am using Google Play Services SDK.

And tried the Demos from developer site.

Is there a way to get(download) all the files from a specific folder?

Any pointer will be of great help. The whole sample code doesn't seem to be complete.

user1537779
  • 2,311
  • 5
  • 28
  • 45

1 Answers1

0

Here is the 'await' version of a method that does something similar (must be run on non-ui thread).

//  list / search all non-trashed files in a folder (globally if 'fldr' is null) 
GoogleApiClient _gac;
public void findAll(String title, String mime, DriveFolder fldr) {
  ArrayList<Filter> fltrs = new ArrayList<Filter>();
  fltrs.add(Filters.eq(SearchableField.TRASHED, false));
  if (title != null)  
    fltrs.add(Filters.eq(SearchableField.TITLE, title));
  if (mime != null)  
    fltrs.add(Filters.eq(SearchableField.MIME_TYPE, mime));
  Query qry = new Query.Builder().addFilter(Filters.and(fltrs)).build(); 
  MetadataBufferResult rslt = (fldr == null) ? Drive.DriveApi.query(_gac, qry).await() : 
                                               fldr.queryChildren(_gac, qry).await();
  if (rslt.getStatus().isSuccess()) {
    MetadataBuffer mdb = null;
    try { 
      mdb = rslt.getMetadataBuffer();
      if (mdb == null) return null;
      for (Metadata md : mdb) {
        if ((md == null) || (!md.isDataValid()) || md.isTrashed()) continue;
        // md gives you the file info    
      }
    } finally { if (mdb != null) mdb.close(); } 
  }
}

There is a bunch of code on the same theme on Github here, but I haven't touched it for awhile now (i.e. no warranties).

Nimantha
  • 6,405
  • 6
  • 28
  • 69
seanpj
  • 6,735
  • 2
  • 33
  • 54
  • I get the error **Filter cannot be resolved to a type**. Is it `Filters`? – user1537779 May 05 '14 at 08:24
  • I'm off-line, can't check it. The code was written ages ago for ver.14 library and was functional. But googlers are known to pull the rug under you (us). Sorry, too far (somewhere in EU) to help right now. What I remember, from the top off my head, there is probably a '.list' method that does not deal with filters. Grep the Github code, there may be something there. – seanpj May 05 '14 at 08:30
  • There is also a GAC class in a different GitHub area (https://github.com/seanpjanson/140319-Accounts/blob/master/GAC.java), that does a lot of stuff, you may be able to dig something out of there (stuff I dumped there just to show how crappy code I can write :-) Enjoy. – seanpj May 05 '14 at 08:39
  • Okay solved it. Have a question, the above code of yours gets files created by my application only. Any other file added using web or other apps are not visible. Is this expected? How can I get all the files(created by other apps as well) of the folder. – user1537779 May 05 '14 at 08:42
  • The only scope in GDAA (Google Drive Android Api) is FILE. There is a File picker in GDAA that may circumvert this, but I don't know much about it. Check Cheryl Simon's answers on SO (http://stackoverflow.com/users/234039/cheryl-simon) to find out more. – seanpj May 05 '14 at 08:46
  • In general, in the GAC class (above), I use both the GDAA and the RESful API (com.google.api.services.drive.Drive _drvSvc), since a lot of functionality is missing in the GDAA (thumbnails, delete, fulltext, ...). The DRIVE_FILE scope also can be substituted by mixing the RESTful with GDAA. – seanpj May 05 '14 at 08:54