繁体   English   中英

Dropbox Sync API错误

[英]Dropbox Sync API errors

我已经从此处下载并安装了适用于Android的Dropbox Sync API: https//www.dropbox.com/developers/sync

我对他们的教程不太了解。 它缺少许多关键变量,因此我必须自己找出它们。 我现在有一个非常凌乱的代码,并且没有很多东西。

private DbxAccountManager mDbxAcctMgr;
static final int REQUEST_LINK_TO_DBX = 0;  // This value is up to you // thanks for telling what it actually does, Dropbox!
DbxPath path = new DbxPath("/test.pdf");


public void onClickLinkToDropbox(View view) {
    mDbxAcctMgr.startLink((Activity)this, REQUEST_LINK_TO_DBX);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_LINK_TO_DBX) {
        if (resultCode == Activity.RESULT_OK) {

            DbxFileSystem dbxFs = DbxFileSystem.forAccount(mDbxAcctMgr.getLinkedAccount()); // try /catch error

            DbxFile testFile = dbxFs.open(path); //try/catch error
            String contents = testFile.readString();

            Log.d("Dropbox Test", "File contents: " + contents); // try / catch error

        } else {
            // ... Link failed or was cancelled by the user.
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}   

这给了我3行错误,说我需要添加try / catch。 但是,当我添加try / catch时,Eclipse告诉我将变量设置为空,这意味着所有函数将只读取null,因此不读取任何内容。

谁能进一步帮助我? Dropbox只是通过给出错误的指示等使我更加困惑。我确信,即使我没有3次try / catch错误,它仍然无法正常工作。

在座的任何人都有使用Dropbox Sync API的经验,并且可以共享一个示例程序,以读取用户Dropbox文件夹中的txt文件吗?

巴特

有关REQUEST_LINK_TO_DBX更多信息,请查看onActivityResult的Android文档: https : //developer.android.com/reference/android/app/Activity.html#onActivityResult (int,int,android.content.Intent)。 它可以帮助您区分不同的活动。

对于一个HelloDropbox示例,建议您查看SDK随附的HelloDropbox示例。 除其他外,它从Dropbox中的文件读取字符串。

这是HelloDropboxActivity.java的相关代码:

try {
    // ...
    DbxFileSystem dbxFs = DbxFileSystem.forAccount(mDbxAcctMgr.getLinkedAccount());
    // ...
    String resultData;
    DbxFile testFile = dbxFs.open(testPath);
    try {
        resultData = testFile.readString();
    } finally {
        testFile.close();
    }
} catch (IOException e) {
    // ...
}

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM