我尝试使用Android核心Api将文件上传到Dropbox,如下所示:Link
private DropboxAPI<AndroidAuthSession> mDBApi;
// And later in some initialization function:
AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
AndroidAuthSession session = new AndroidAuthSession(appKeys, ACCESS_TYPE);
mDBApi = new DropboxAPI<AndroidAuthSession>(session);
// MyActivity below should be your activity class name
mDBApi.getSession().startOAuth2Authentication(MyActivity.this);
protected void onResume() {
super.onResume();
if (mDBApi.getSession().authenticationSuccessful()) {
try {
// Required to complete auth, sets the access token on the session
mDBApi.getSession().finishAuthentication();
String accessToken = mDBApi.getSession().getOAuth2AccessToken();
} catch (IllegalStateException e) {
Log.i("DbAuthLog", "Error authenticating", e);
}
}
}
File path = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_MOVIES);
File file = new File(path, "/" + "fname");
FileInputStream inputStream = null;
String text = "Hello world";
try {
BufferedWriter output = new BufferedWriter(new FileWriter(file));
output.write(text);
output.close();
inputStream = new FileInputStream(file);
} catch ( IOException e ) {
e.printStackTrace();
}
try {
com.dropbox.client2.DropboxAPI.Entry response = mDBApi.putFile("/magnum-opus.txt", inputStream, file.length(), null, null);
} catch (DropboxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我得到Source not found.
行后:
com.dropbox.client2.DropboxAPI.Entry response = mDBApi.putFile("/magnum-opus.txt", inputStream, file.length(), null, null);
它不会继续下一行