Dropbox Sync Api。第一次没有看到Dropbox上的文件

时间:2013-06-05 13:30:01

标签: android dropbox

我有一个DropboxHelper类正在处理从dropbox下载和上传。 下载工作正常,但是当我第一次调用代码时尝试从dropbox上传时。以下行为false

if (dropboxFileSystem.isFile(dropboxPath)) {

}

返回false。告诉应用再试一次,这次它会看到该文件并将其上传到应用。下面是我在课堂上使用的一些代码。调试似乎提示dropbox api第一次没有完成启动/同步

public class DropBoxHelper {


public DropBoxHelper(Context pContext) {

        context = pContext;
        defineVariables();

}

    private void defineVariables() {

        dropboxAccountManager = DbxAccountManager.getInstance(context.getApplicationContext(), DROPBOX_APP_KEY, DROPBOX_APP_SECRET);
        dropboxPath = new DbxPath(DbxPath.ROOT, DROPBOX_FILE_NAME);


    }

public boolean importFromDropbox() {

        try {

            dropboxFileSystem = DbxFileSystem.forAccount(dropboxAccountManager.getLinkedAccount());

            if (dropboxFileSystem.isFile(dropboxPath)) {

                DbxFile databaseFileonDropbox = dropboxFileSystem.open(dropboxPath);

                try {

                    // Do Copy

                } finally {

                    Log.i(DEBUG_TAG, "Closing File");
                    databaseFileonDropbox.close();

                }

}

关于复制首次失败的原因的任何想法。 感谢

1 个答案:

答案 0 :(得分:4)

我不是百分百确定,但我相信您需要使用dropboxFileSystem.awaitFirstSync()来确保在尝试查找文件之前至少发生了一次与服务器的同步。

另一种方法是直接调用dropboxFileSystem.open(...)并处理在文件不存在时引发的异常。