Get list of files from a specific folder in google drive

前端 未结 1 1235
遥遥无期
遥遥无期 2021-01-23 09:38

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 p

相关标签:
1条回答
  • 2021-01-23 10:02

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

    0 讨论(0)
提交回复
热议问题