Get list of files from a specific folder in google drive

守給你的承諾、 提交于 2019-12-31 03:52:06

问题


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:


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).



来源:https://stackoverflow.com/questions/23460799/get-list-of-files-from-a-specific-folder-in-google-drive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!