Android에서 주어진 파일에 http 연결을 열고 다운로드 할 수 있기를 원합니다. 어떤 시점에서 다운로드를 일시 중지하고 나중에 다시 시작할 수 있어야합니다. Android에서이 기능은 어떻게 구현됩니까? 나는 다시 다운로드를 시작하고 싶지 않다.http 연결 일시 중지/다시 시작
7
A
답변
1
는 이러한 다운로더는 here 게시되어 있습니다
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);
}
는이 http://stackoverflow.com/questions/6237079/resume-http-file-download-in-java – laxonline
@laxonline 큰 감사를 참조 되세요 ! 이 질문을 답으로 게시하면 동의하고이를 닫을 수 있습니다. –