Dropbox API Android列出了目录中内容的内容

时间:2013-09-17 08:01:32

标签: android api dropbox

我想使用 Android API 列出 Dropbox 目录内容的内容。 我尝试在 for 循环中使用 dirEntry.contents(),如下所示:

Entry rootDirEnt = mApi.metadata(mPath, 1000, null,
                true, null);

        if (!rootDirEnt.isDir || rootDirEnt.contents == null) {

            // It's not a directory, or there's nothing in it
            mErrorMsg = "No files available in Dropbox";
            return false;
        }

        for (Entry childDirEnt : rootDirEnt.contents) {

            // check if it still exists
            if (childDirEnt.isDir && !childDirEnt.isDeleted
                    && childDirEnt.contents != null) {

                // childDirEnt contents is already null, even though there are files inside this directory
                for (Entry fileEnt : childDirEnt.contents) {

                    // do smth with file
                    if (isCancelled()) {
                        return false;
                    } else {
                        publishProgress();
                    }
                }
            }
        }

所以我想到使用新路径再次使用mApi.metadata(),但我的问题是:如果不为root目录中的每个目录调用medata(),我不能这样做吗? (可能使用内容调用或smth ..)

1 个答案:

答案 0 :(得分:1)

您可以在找到的每个目录上再次呼叫metadata。通常,除非由用户操作驱动,否则Dropbox不会像这样递归地调用metadata。请参阅https://www.dropbox.com/developers/core/bestpractices

您可以使用delta API。第一次拨打电话时,它会返回您的应用在用户Dropbox中可以访问的所有内容的完整列表。