简体   繁体   English

适用于Android的云端硬盘API:如何列出Google云端硬盘文件夹中的每个条目(以及不是由我的应用创建的条目)

[英]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. 我正在使用Google云端硬盘文件夹备份我的应用中的某些信息。 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). 我不使用App Folder,因为我希望用户能够将文件上传到同一文件夹(例如,上传其他人获得的备份)。

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. Google云端硬盘SDK无法实现。 You should use http-requests for it. 您应该为此使用http-requests。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Google Drive Android API中获取已创建文件夹的DriveId - How to get DriveId of created folder in Google Drive Android API 如何使用Google Drive Android API更改在Google云端硬盘中创建的文件夹或文件的权限? - How to change permission of folder or file created in Google Drive using Google Drive Android API? Google Drive Android API-Google Drive应用 - Google Drive Android API - Google Drive App 在Android中将已创建的文件夹添加到Google云端硬盘 - Adding an already created folder to Google Drive in Android Google Drive Android API - 在App文件夹中共享文件? - Google Drive Android API - Sharing files in App folder? Android Google Drive API从应用程序文件夹下载文件 - Android Google Drive API download files from app folder Android Google Drive API上传到我的公共文件夹 - Android Google Drive API upload to my public folder 如何以编程方式在Google驱动器中的Google驱动器的App文件夹中创建文件夹 - How to Create a Folder in App Folder in google drive in Android Programmatically Google Drive Android API如何将音频文件上传到我的驱动器? 如何同步驱动器文件? - Google Drive Android API how to upload a audio file to my drive ? How to sync drive files? 使用Google Drive API - 如何在根文件夹中显示文件夹列表 - Using Google Drive API - how to show a list of folders in root folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM