简体   繁体   中英

Android | Google Drive | Display files in folder

I've searched on Google but I don't find anything that can really help me.
I've tested some codes.

One test is this: Get list of files from a specific folder in google drive but it show only 3 files/folders (in // md gives you the file info , I've added md.getTitle() ) or nothing, I don't know why.

Then I've tried with this: https://github.com/googledrive/android-demos/blob/master/app/src/main/java/com/google/android/gms/drive/sample/demo/ListFilesInFolderActivity.java , changed the last method. I've used the MetadataBufferResult result so:

MetadataBuffer metadataBuffer = result.getMetadataBuffer();
Log.d("DRIVE","size: "+metadataBuffer.getCount());
metadataBuffer.release();

And the "size" is like the previus test: it is 3, 0 or 1, but there are more folder/files.

How can I list all files in a folder? Do you give me an example?

If you simply want to get all direct children of a particular folder, you can use DriveFolder.listChildren as discussed in Working with Folders documentation .

However, to list all files of a specific folder, it would be better to use Files: list method with q parameter to filter your search as given in Search for Files . You can send a request with the following format:

GET https://www.googleapis.com/drive/v2/files?q="'<FOLDER_ID>' in parents"

This sample request returns all files of the specified ID and also includes files with trashed=true in the results. Use the trashed=false query parameter to filter these from the results.

Important Note: Every request your application sends to the Drive API must include an authorization token as discussed in the Drive API documentation .

Here are some related SO posts which might also help:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM