Android Dropbox Sync API startLink()方法不工作

Android Dropbox Sync API startLink()方法不工作,android,dropbox-api,Android,Dropbox Api,我正在开发一个Android应用程序,它使用Dropbox同步API上传文件。我已经在Dropbox上创建了应用程序,获得了应用程序密钥和应用程序密钥。我已经包括了所有必要的库,在我的活动代码和清单中设置了正确的键。我的应用程序类似于文档中提供的HelloDropbox示例,但当我单击“链接到Dropbox”按钮(该按钮应显示输入我的Dropbox凭据的位置)时,什么也没有发生。以下是源代码: package com.diamondtrust66.helix.player; import jav

我正在开发一个Android应用程序,它使用Dropbox同步API上传文件。我已经在Dropbox上创建了应用程序,获得了应用程序密钥和应用程序密钥。我已经包括了所有必要的库,在我的活动代码和清单中设置了正确的键。我的应用程序类似于文档中提供的HelloDropbox示例,但当我单击“链接到Dropbox”按钮(该按钮应显示输入我的Dropbox凭据的位置)时,什么也没有发生。以下是源代码:

package com.diamondtrust66.helix.player;
import java.io.File;
import java.io.IOException;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.dropbox.client2.DropboxAPI;
import com.dropbox.sync.android.DbxAccountManager;
import com.dropbox.sync.android.DbxFile;
import com.dropbox.sync.android.DbxFileInfo;
import com.dropbox.sync.android.DbxFileSystem;
import com.dropbox.sync.android.DbxPath;

public class HelixPlayer extends Activity {

private static final String appKey = "1234-my-key";
private static final String appSecret = "1234-my-secret";

private static final int REQUEST_LINK_TO_DBX = 0;

private TextView mTestOutput;
private Button mLinkButton;
private DbxAccountManager mDbxAcctMgr;
private DropboxAPI<?> mDBApi;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_helix_player);
    mTestOutput = (TextView) findViewById(R.id.test_output);
    mLinkButton = (Button) findViewById(R.id.link_button);
    mLinkButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            onClickLinkToDropbox();
        }
    });

    mDbxAcctMgr = DbxAccountManager.getInstance(getApplicationContext(), appKey, appSecret);
}

@Override
protected void onResume() {
    super.onResume();
    if (mDbxAcctMgr.hasLinkedAccount()) {
        showLinkedView();
        doDropboxTest();
    } else {
        showUnlinkedView();
    }
}

private void showLinkedView() {
    mLinkButton.setVisibility(View.GONE);
    mTestOutput.setVisibility(View.VISIBLE);
}

private void showUnlinkedView() {
    mLinkButton.setVisibility(View.VISIBLE);
    mTestOutput.setVisibility(View.GONE);
}

private void onClickLinkToDropbox() {
    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) {
            doDropboxTest();
        } else {
            Toast.makeText(getApplicationContext(), "FAILURE", Toast.LENGTH_LONG).show();
            mTestOutput.setText("Link to Dropbox failed or was cancelled.");
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

private void doDropboxTest() {
    try {
        final String TEST_DATA = "Hello Dropbox";
        final String TEST_FILE_NAME = "be like that.mp3";
        DbxPath testPath = new DbxPath(DbxPath.ROOT, TEST_FILE_NAME);

        // Create DbxFileSystem for synchronized file access.
        DbxFileSystem dbxFs = DbxFileSystem.forAccount(mDbxAcctMgr.getLinkedAccount());





        // Print the contents of the root folder.  This will block until we can
        // sync metadata the first time.
        List<DbxFileInfo> infos = dbxFs.listFolder(DbxPath.ROOT);
        mTestOutput.setText("\nContents of app folder:\n");
        for (DbxFileInfo info : infos) {
            mTestOutput.append("    " + info.path + ", " + info.modifiedTime + '\n');
        }

        // Create a test file only if it doesn't already exist.
        if (!dbxFs.exists(testPath)) {
            DbxFile testFile = dbxFs.create(testPath);
            try {

                File myFile = new File("/mnt/sdcard/alarms/be like that.mp3");
                //testFile.writeString(TEST_DATA);
                testFile.writeFromExistingFile(myFile, false);
            } finally {
                testFile.close();
            }
            mTestOutput.append("\nCreated new file '" + testPath + "'.\n");
        }

        // Read and print the contents of test file.  Since we're not making
        // any attempt to wait for the latest version, this may print an
        // older cached version.  Use getSyncStatus() and/or a listener to
        // check for a new version.
        /*if (dbxFs.isFile(testPath)) {
            String resultData;
            DbxFile testFile = dbxFs.open(testPath);
            try {
                resultData = testFile.readString();
            } finally {
                testFile.close();
            }
            mTestOutput.append("\nRead file '" + testPath + "' and got data:\n    " + resultData);
        } else if (dbxFs.isFolder(testPath)) {
            mTestOutput.append("'" + testPath.toString() + "' is a folder.\n");
        }*/
    } catch (IOException e) {
        mTestOutput.setText("Dropbox test failed: " + e);
    }
}
package com.diamondtrust66.helix.player;
导入java.io.File;
导入java.io.IOException;
导入java.util.List;
导入android.app.Activity;
导入android.content.Intent;
导入android.os.Bundle;
导入android.view.view;
导入android.view.view.OnClickListener;
导入android.widget.Button;
导入android.widget.TextView;
导入android.widget.Toast;
导入com.dropbox.client2.DropboxAPI;
导入com.dropbox.sync.android.DbxAccountManager;
导入com.dropbox.sync.android.DbxFile;
导入com.dropbox.sync.android.DbxFileInfo;
导入com.dropbox.sync.android.DbxFileSystem;
导入com.dropbox.sync.android.DbxPath;
公共类HelixPlayer扩展活动{
私有静态最终字符串appKey=“1234我的密钥”;
私有静态最终字符串appSecret=“1234我的秘密”;
私有静态最终int请求链接到DBX=0;
私有文本视图mTestOutput;
私有按钮mLinkButton;
私有DbxAccountManager mDbxAcctMgr;
私有DropboxAPI mDBApi;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u helix\u player);
mTestOutput=(TextView)findViewById(R.id.test\u输出);
mLinkButton=(按钮)findViewById(R.id.link_按钮);
setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
onClickLinkToDropbox();
}
});
mDbxAcctMgr=DbxAccountManager.getInstance(getApplicationContext(),appKey,appSecret);
}
@凌驾
受保护的void onResume(){
super.onResume();
if(mDbxAcctMgr.hasLinkedAccount()){
showLinkedView();
doDropboxTest();
}否则{
showUnlinkedView();
}
}
私有void showLinkedView(){
mLinkButton.setVisibility(View.GONE);
mTestOutput.setVisibility(View.VISIBLE);
}
私有void showUnlinkedView(){
mLinkButton.setVisibility(View.VISIBLE);
mTestOutput.setVisibility(View.GONE);
}
私有void onClickLinkToDropbox(){
mDbxAcctMgr.startLink((活动)此,请求链接到DBX);
}
@凌驾
ActivityResult上的公共void(int请求代码、int结果代码、意图数据){
if(requestCode==请求链接到DBX){
if(resultCode==Activity.RESULT\u确定){
doDropboxTest();
}否则{
Toast.makeText(getApplicationContext(),“FAILURE”,Toast.LENGTH_LONG.show();
setText(“到Dropbox的链接失败或被取消”);
}
}否则{
super.onActivityResult(请求代码、结果代码、数据);
}
}
私有无效doDropboxTest(){
试一试{
最终字符串测试\u DATA=“Hello Dropbox”;
最后的字符串测试文件\u NAME=“belike that.mp3”;
DbxPath testPath=newdbxpath(DbxPath.ROOT,TEST\u文件名);
//创建用于同步文件访问的DbxFileSystem。
DbxFileSystem dbxFs=DbxFileSystem.forAccount(mDbxAcctMgr.getLinkedAccount());
//打印根文件夹的内容。这将阻止,直到我们可以
//第一次同步元数据。
List infos=dbxFs.listFolder(DbxPath.ROOT);
mTestOutput.setText(“\n应用程序文件夹的内容:\n”);
for(DbxFileInfo:infos){
mTestOutput.append(“+info.path+”,“+info.modifiedTime+”\n');
}
//仅当测试文件不存在时才创建它。
如果(!dbxFs.exists(testPath)){
DbxFile testFile=dbxFs.create(testPath);
试一试{
File myFile=新文件(“/mnt/sdcard/alarms/be like that.mp3”);
//testFile.writeString(测试数据);
testFile.writeFromExistingFile(myFile,false);
}最后{
testFile.close();
}
MTESOutput.append(“\n创建的新文件”“+testPath+”)。\n”);
}
//读取并打印测试文件的内容。因为我们没有
//如果试图等待最新版本,则可能会打印
//较旧的缓存版本。请使用getSyncStatus()和/或侦听器
//检查新版本。
/*if(dbxFs.isFile(testPath)){
字符串结果数据;
DbxFile testFile=dbxFs.open(testPath);
试一试{
resultData=testFile.readString();
}最后{
testFile.close();
}
附加(“\n读取文件”“+testPath+”,并获取数据:\n“+resultData);
}else if(dbxFs.isFolder(testPath)){
mTestOutput.append(“”+testPath.toString()+“”是一个文件夹。\n”);
}*/
}捕获(IOE异常){
mTestOutput.setText(“Dropbox测试失败:+e”);
}
}

}

您是否能够在遇到此问题的同一模拟器/设备上运行未修改的Hello Dropbox示例?您也可以尝试将示例中的应用程序密钥/密码替换为您自己的。如果这些也失败了,则可能是设备的配置有问题,导致API无法启动浏览器来完成身份验证。如果这个例子有效,但你的应用程序没有,那么我会怀疑有什么配置错误。你能用log语句检查一下你对startLink()的调用是否真的发生了吗?在那一点之后,你在LogCat中看到什么了吗


进一步调试此问题的最佳方法可能是打开支持票证。在这里使用API支持链接:

我遇到了同样的问题,st