我在我的示例应用程序中集成了Dropbox sdk。除了在屏幕上显示上传进度外,一切都很完美。我正在使用DropboxAPI putFile API在Dropbox上进行归档。此API提供了ProgressListener,它在onProgress方法中发布了进度。我在这里遇到的问题是onProgress似乎没有返回正确的值。例如下面是我看到的日志。它只是在显示上一个日志并且文件上传成功后停止。我试图找回一个回调,它会让我知道文件上传已经完成。
04-20 09:51:30.041 27244-27452/google.dropboxfilesample I/vipul﹕ 2048<===>2330600
04-20 09:51:31.801 27244-27452/google.dropboxfilesample I/vipul﹕ 327680<===>2330600
04-20 09:51:32.851 27244-27452/google.dropboxfilesample I/vipul﹕ 473088<===>2330600
04-20 09:51:33.851 27244-27452/google.dropboxfilesample I/vipul﹕ 604160<===>2330600
04-20 09:51:34.561 27244-27452/google.dropboxfilesample I/vipul﹕ 753664<===>2330600
04-20 09:51:35.211 27244-27452/google.dropboxfilesample I/vipul﹕ 868352<===>2330600
04-20 09:51:35.881 27244-27452/google.dropboxfilesample I/vipul﹕ 1011712<===>2330600
04-20 09:51:36.381 27244-27452/google.dropboxfilesample I/vipul﹕ 1277952<===>2330600
04-20 09:51:36.911 27244-27452/google.dropboxfilesample I/vipul﹕ 1441792<===>2330600
04-20 09:51:37.701 27244-27452/google.dropboxfilesample I/vipul﹕ 1761280<===>2330600
04-20 09:51:38.201 27244-27452/google.dropboxfilesample I/vipul﹕ 2201600<===>2330600
private void uploadFile() throws FileNotFoundException, DropboxException {
final File file = new File(Environment.getExternalStorageDirectory(), "sample.mp3");
final ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setProgressStyle(progressDialog.STYLE_HORIZONTAL);
progressDialog.setMax((int) file.length());
progressDialog.show();
new Thread() {
@Override
public void run() {
try {
FileInputStream inputStream = new FileInputStream(file);
final DropboxAPI.Entry response = mDBApi.putFile("/sample.mp3", inputStream,
file.length(), null, new ProgressListener() {@
Override
public void onProgress(final long bytes, final long total) {
Log.d("vipul", bytes + "<===>" + total);
}
});
Log.d("vipul", "The uploaded file's rev is: " + response.rev);
} catch (DropboxException dropboxException) {
if (progressDialog.isShowing()) {
progressDialog.dismiss();
}
dropboxException.printStackTrace();
} catch (FileNotFoundException e) {
if (progressDialog.isShowing()) {
progressDialog.dismiss();
}
e.printStackTrace();
}
}
}.start();
}
如果有人能指出我正确的方向,那就太好了。 谢谢