问题
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