我是新手使用dropbox首先我试图使用android studio将文件从android手机上传到Dropbox。首先我验证它。在调试期间我得到它是正确的意味着认证然后我上传文件我也创建应用程序机器人。但经过所有处理后,它显示"删除从未存在过的连接!"在logcat窗口和文件没有上传我不知道有什么问题可以任何人帮助我。提前感谢。 代码:我使用以下代码
在这里输入代码
manifest资源配置文件
<activity
android:name="com.dropbox.client2.android.AuthActivity"
android:configChanges="orientation|keyboard"
android:launchMode="singleTask">
<intent-filter>
<!-- Change this to be db- followed by your app key -->
<data android:scheme="db-v4n6dxu3uufev8w" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service
android:name="com.dropbox.sync.android.DbxSyncService"
android:enabled="true"
android:exported="false"
android:label="Dropbox Sync" />
</application>
MainActivity
DropboxAPI mDBApi; static final String ACCESS_TOKEN =&#34; xxxxxxxxxx&#34 ;;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
login = (Button) findViewById(R.id.login);
login.setOnClickListener(this);
Upload = (Button) findViewById(R.id.Upload);
Upload.setOnClickListener(this);
loggedIn(false);
AppKeyPair appKeys = new AppKeyPair(DROPBOX_APP_KEY, DROPBOX_APP_SECRET);
// session.setOAuth2AccessToken(ACCESS_TOKEN);
SharedPreferences sh = getSharedPreferences(DROP_BOX_NAME, 0);
String key = sh.getString(DROPBOX_APP_KEY, null);
String secret = sh.getString(DROPBOX_APP_SECRET, null);
if (key != null && secret != null) {
AccessTokenPair pair = new AccessTokenPair(key, secret);
session = new AndroidAuthSession(appKeys, access, pair);
} else {
session = new AndroidAuthSession(appKeys, access);
}
mDBApi = new DropboxAPI(session);
session.setOAuth2AccessToken(ACCESS_TOKEN);
// session.finishAuthentication();
}
protected void onResume() {
super.onResume();
AndroidAuthSession session = (AndroidAuthSession) mDBApi.getSession();
if (mDBApi.getSession().authenticationSuccessful()) {
try {
mDBApi.getSession().finishAuthentication();
TokenPair token = session.getAccessTokenPair();
SharedPreferences prefs = getSharedPreferences(DROP_BOX_NAME, 0);
SharedPreferences.Editor edit = prefs.edit();
edit.putString(DROPBOX_APP_KEY, token.key);
edit.putString(DROPBOX_APP_SECRET, token.secret);
edit.commit();
loggedIn(true);
Log.i("DbAuthLog", "Authenticating OK!");
} catch (IllegalStateException e) {
Log.i("DbAuthLog", "Error authenticating", e);
} catch (Exception e) {
e.printStackTrace();
}
} else {
Log.i("DbAuthLog", "No authenticating");
}
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.login:
if (userlogin) {
mDBApi.getSession().unlink();
loggedIn(false);
} else {
((AndroidAuthSession) mDBApi.getSession()).startAuthentication(MainActivity.this);
}
break;
case R.id.Upload:
UploasdFile uploadFile = new UploasdFile(mDBApi, DROP_BOX_FILE_DIR, this);
uploadFile.execute();
break;
default:
break;
}
}
public void loggedIn(boolean isLogged) {
userlogin = isLogged;
Upload.setEnabled(isLogged);
login.setText(isLogged ? "Log out" : "Log in");
}
上传文件
protected Boolean doInBackground(Void... params) {
try {
try {
File newFolder = new File(Environment.getExternalStorageDirectory(), "TestFolder");
if (!newFolder.exists()) {
newFolder.mkdir();
}
File file = new File(newFolder, "MyTest" + ".txt");
file.createNewFile();
FileWriter write = null;
write = new FileWriter(file);
write.append("This is some random text I write to test this application");
write.flush();
write.close();
System.out.println("File =" + file);
System.out.println("mpath =" + mPath);
System.out.println("gfUploads.length()v" + file.length());
if (newFolder.exists()) {
FileInputStream fis = new FileInputStream(file);
DropboxAPI.Entry newEntry = mApi.putFileOverwrite("MyTest.txt", fis, file.length(), null);
System.out.println("eupload2");
} else {
System.out.println(" nottt okk");
}
return true;
} catch (DropboxIOException e) {
// Happens all the time, probably want to retry automatically.
mErrorMsg = "Network error. Try again.";
System.out.println("error= "+ e);
} catch (DropboxParseException e) {
// Probably due to Dropbox server restarting, should retry
mErrorMsg = "Dropbox error. Try again.";
System.out.println("error1= "+ e);
} catch (DropboxException e) {
// Unknown error
mErrorMsg = "Unknown error. Try again.";
System.out.println("error2= "+ e);
} catch (IOException e) {
e.printStackTrace();
System.out.println("error3= " + e);
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("error4= " + e);
}
return false;
}
Logcat窗口中的输出
答案 0 :(得分:0)
通过“删除从未存在的连接,我找到了问题的解决方案!在dropbox上传文件时的logcat&#34;或者&#34;没有从android studio&#34;上载Dropbox上的文件。这个问题背后有很多原因,比如可能没有空间在Dropbox上存储我们的数据,我们无法通过Dropbox等进行身份验证。但在我的情况下存在身份验证问题实际上是将文件上传到我们共享的用户Dropbox应用必须拥有Dropbox中的帐户,并且必须拥有访问我们应用的权限。
由于