获取文件列表在谷歌驱动器中的特定文件夹 [英] Get list of files from a specific folder in google drive

查看:193
本文介绍了获取文件列表在谷歌驱动器中的特定文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用谷歌Play服务SDK。

I am using Google Play Services SDK.

和尝试演示从开发者网站。

有没有办法从一个特定的文件夹得到(下载)的所有文件?

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

任何指针将有很大的帮助。整个样本code似乎不完整的。

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

推荐答案

下面是做类似的东西(必须在非UI线程中运行)方法的等待的版本。

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

希望它能帮助,对的 Github上这里,但我还没有碰过它一段时间了(即无担保)。

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

这篇关于获取文件列表在谷歌驱动器中的特定文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆