2

我正在尝试使用进度条从下载示例中修改 koush 的代码,以使其写入 FileOutputStream 而不是 File,但是 eclipse 给了我以下错误:

ResponseFuture 类型的方法 progressHandler(new ProgressCallback(){}) 未定义

这是代码:

File file = new File(DownloadPath, uri.getLastPathSegment());
FileOutputStream fos = null;
try {
    fos = new FileOutputStream(file);
} catch (FileNotFoundException e1) {
    // TODO Auto-generated catch block
}

Future<FileOutputStream> downloading = Ion.with(getApplicationContext())
    .load(uri)
    .write(fos)
    .progressHandler(new ProgressCallback() { 
        @Override
        public void onProgress(int downloaded, int total) {
            // inform the progress bar of updates in progress
        }
    })
    .setCallback(new FutureCallback<FileOutputStream>() {
       @Override
        public void onCompleted(Exception e, FileOutputStream file) {
            // download done...
            // do stuff with the File or error
        }
    });     
4

1 回答 1

7

你好像弄乱了顺序。请试试这个:

Future<FileOutputStream> downloading = Ion.with(getApplicationContext())
    .load("http://example.com/test.txt")
    .progressHandler(new ProgressCallback() { 
        @Override
        public void onProgress(int downloaded, int total) {
            // inform the progress bar of updates in progress
        }
    })
    .write(fos)
    .setCallback(new FutureCallback<FileOutputStream>() {
       @Override
        public void onCompleted(Exception e, FileOutputStream file) {
            // download done...
            // do stuff with the File or error
        }
    });
于 2014-05-22T10:03:10.603 回答