Get list of files from a specific folder in google

2019-03-01 00:51发布

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.

1条回答
淡お忘
2楼-- · 2019-03-01 00:58

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(); } 
  }
}

Hope it helps, 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).

查看更多
登录 后发表回答