答案 0 :(得分:0)
这是' await'执行类似操作的方法的版本(必须在非ui线程上运行)。
// 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 here上的同一主题上有一堆代码,但我暂时没有触及它(即没有保修)。