简体   繁体   中英

Drive API for Android: how to list every entry in Google Drive folder (also those not created by my app)

I'm using a Google Drive folder to backup some info from my app. I don't use App Folder since I want the user to be able to upload files to that same folder (for example, to upload a backup obtained by somebody else).

The code I use is the following:

Query query = new Query.Builder()
             .addFilter(Filters.eq(SearchableField.TITLE, backupName))
             .build();

DriveApi.MetadataBufferResult result =
        mDriveFolder
                .queryChildren(mGoogleApiClient, query)
                .await();

if (result == null || !result.getStatus().isSuccess()) {
    return null;
}

MetadataBuffer buffer = result.getMetadataBuffer();
if (buffer.getCount() == 0) {
    buffer.close();

    return null;
}
Metadata m = buffer.get(0); //get first

This way, I can find the backup file only if it was uploaded by my app through the backup function. If I upload to my Drive a file from my Desktop, or create a new document just for testing purposes, it is not found. (and from Drive I can correctly see all the files, either from my app or not, and I am the owner).

So, I tried to list and log all the folder contents:

DriveApi.MetadataBufferResult result = mDriveFolder.listChildren(mGoogleApiClient).await();

if (result == null || !result.getStatus().isSuccess()) {
    return null;
}

MetadataBuffer buffer = result.getMetadataBuffer();

for(Metadata m: buffer){
    Log.d(TAG, m.getTitle()+" - "+m.getOriginalFilename());
}

and only the files uploaded by my app are logged.

So, how can I get every content of my folder from the app, irrespective of its source? Am I missing something?

It is not possible with Google Drive SDK. You should use http-requests for it.

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