android - Dropbox 同步 API。第一次没有在 Dropbox 上看到文件

标签 android dropbox

我有一个 DropboxHelper 类,用于处理从 Dropbox 下载和上传。 下载工作正常但是当我第一次调用代码时尝试从保管箱上传。以下行是错误的

if (dropboxFileSystem.isFile(dropboxPath)) {

}

它返回错误。告诉应用程序重试,这次它会看到文件并将其上传到应用程序。下面是我在类里面使用的一些代码。调试似乎表明 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();

                }

}

关于为什么复制第一次失败的任何想法。 谢谢

最佳答案

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

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

关于android - Dropbox 同步 API。第一次没有在 Dropbox 上看到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16941271/

相关文章:

android - Snackbar 顶部的 float 操作按钮。如何?

android - Android 中的 onAnimationEnd 之后调用 applyTransformation

android - 将广播接收器限制为应用程序

java - 如何在 Java 中将 dropbox 文件夹与 Amazon S3 同步?

ubuntu - 在 ubuntu linux 中同步 dropbox 和 xampp htdocs,不包括临时文件

javascript - 使用/files_put javascript 将文件上传到 dropBox

android - aapt完成,退出值非零127

android 从 List Activity 切换到 Activity

python - 从 Microsoft Flow 触发运行 Python