1

我在 Android 上使用 Google Drive SDK v2 来获取根文件夹列表。目前我看到了这些必需的步骤——它们似乎永远加载。没有更快的方法吗?

我尝试使用带有 q= 参数的搜索,但我没有让它工作(FileList 与 Files.List) - 不同的 API 级别?

FileList files = drive.files().list().setQ("'root' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false");

这就是我目前所做的:

About about = drive.about().get().execute();
if (about != null) {
    ChildList childList = drive.children().list(about.getRootFolderId()).execute();
    if (childList != null) {
        List<ChildReference> listChildReference = childList.getItems();
        for (ChildReference childReference : listChildReference) {
            File file = drive.files().get(childReference.getId()).execute();
            if (file != null) {
                String fileExtension = file.getFileExtension();
                String mimeType = file.getMimeType();
                if (mimeType != null
                        && mimeType.equals("application/vnd.google-apps.folder")
                        && (fileExtension == null || fileExtension.equals(""))) {
                    Log.d(this.getClass().getName(), file.getTitle());
                }
            }
        }
    }
}

Android 应用程序最快的是什么?

提前致谢。

4

2 回答 2

1

个人的看法是避免使用Drive SDK,直接调用REST API。这是一个相当简单的 API,而且文档的结构方式,无论如何你都必须理解它才能使用 SDK。您的好处是,如果某些事情不起作用,您可以直接将您的应用程序与网络上发生的事情进行比较并解决任何问题。

于 2012-09-18T15:19:44.270 回答
0

找到了:

@Override
protected ArrayList<File> doInBackground(final Void... voids) {
    ArrayList<File> result = new ArrayList<File>();

    Files.List request = null;

    boolean ok = true;

    do {
        try {
            request = drive
                    .files()
                    .list()
                    .setMaxResults(200)
                    .setQ("'root' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false");
            FileList files = request.execute();

            result.addAll(files.getItems());
            request.setPageToken(files.getNextPageToken());
        } catch (IOException exception) {
            ok = false;
        }
    } while (ok && request.getPageToken() != null && request.getPageToken().length() > 0);

    return result;
}
于 2012-09-18T18:46:59.417 回答