继续下载android
我试图寻找一些方法来帮助恢复下载,我发现了以下代码。我不明白这句话的意思继续下载android,android,download,Android,Download,我试图寻找一些方法来帮助恢复下载,我发现了以下代码。我不明白这句话的意思 if(ISSUE_DOWNLOAD_STATUS.intValue()==ECMConstant.ECM_DOWNLOADING) 这里的ECMConstant是什么 HttpURLConnection connection = (HttpURLConnection) url.openConnection(); if(ISSUE_DOWNLOAD_STATUS.intValue()==ECMConstant.ECM_D
if(ISSUE_DOWNLOAD_STATUS.intValue()==ECMConstant.ECM_DOWNLOADING)
这里的ECMConstant是什么
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
if(ISSUE_DOWNLOAD_STATUS.intValue()==ECMConstant.ECM_DOWNLOADING){
File file=new File(DESTINATION_PATH);
if(file.exists()){
downloaded = (int) file.length();
connection.setRequestProperty("Range", "bytes="+(file.length())+"-");
}
}else{
connection.setRequestProperty("Range", "bytes=" + downloaded + "-");
}
connection.setDoInput(true);
connection.setDoOutput(true);
progressBar.setMax(connection.getContentLength());
in = new BufferedInputStream(connection.getInputStream());
fos=(downloaded==0)? new FileOutputStream(DESTINATION_PATH): new FileOutputStream(DESTINATION_PATH,true);
bout = new BufferedOutputStream(fos, 1024);
byte[] data = new byte[1024];
int x = 0;
while ((x = in.read(data, 0, 1024)) >= 0) {
bout.write(data, 0, x);
downloaded += x;
progressBar.setProgress(downloaded);
}
谢谢。ECMConstant可以是任何东西。。。如果没有ECMConstant的完整代码或库,就无法知道它是什么 如果您怀疑如何恢复下载,那么您需要做的一切就是处理标头、请求属性或服务器恢复下载所需的内容,如下所示:
Map<String, String> headers = new HashMap<String, String>();
if (isResuming) {
File fileToResume = new File(filePath);
if (fileToResume.exists()) {
headers.put("Range", "bytes=" + fileToResume.length() + "-");
}
}
Map headers=newhashmap();
如果(isResuming){
File fileToResume=新文件(filePath);
如果(fileToResume.exists()){
headers.put(“Range”,“bytes=“+fileToResume.length()+”-”;
}
}
您的标志是在哪里继续下载或不继续下载。您好,您的问题解决了吗?我现在也有同样的问题。这个dsn对我不起作用,是他们的任何其他方法来恢复下载。如果你的下载服务器支持它,这个方法可以使用。