gpt4 book ai didi

使用 FileOutputStream 使用进度条下载 Android ION

转载 作者:太空狗 更新时间:2023-10-29 16:03:23 25 4
gpt4 key购买 nike

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

The method progressHandler(new ProgressCallback(){}) is undefined for the type ResponseFuture

代码如下:

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
}
});

最佳答案

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

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
}
});

关于使用 FileOutputStream 使用进度条下载 Android ION,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23802849/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com