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);
}
관련 문제
- 1. ActiveMQ : 연결 풀링을 사용할 때 소비자 일시 중지/다시 시작
- 2. 일시 중지 시작 div onmouseover
- 3. NSTimer 일시 정지/다시 시작
- 4. Evaporate.js 일시 중지/다시 시작
- 5. WinInet의 HTTP 연결 정보
- 6. HTTP 연결
- 7. HTTP 연결 풀링이 가능합니까?
- 8. 시작 및 일시 중지 간격 onclick
- 9. jquery spritefy 일시 중지 및 다시 시작
- 10. 네트워크 연결 중지/시작
- 11. AsyncTasks를 일시 중지했다가 다시 시작 하시겠습니까? (안드로이드)
- 12. 목록보기 일시 중지 및 다시 시작
- 13. 시작/자바 이력서/방법을 일시 중단
- 14. Ragel에서 파싱 일시 중지 및 다시 시작
- 15. Jenkins의 프로젝트 일시 중지 및 다시 시작
- 16. 일시 중지 후 THREE.js에서 게임 다시 시작
- 17. iOS에서 애니메이션 일시 중지 및 다시 시작
- 18. WPF에서 실행 일시 중지 및 다시 시작
- 19. 시작 및 일시 중지 버튼 사용 방법
- 20. 오디오 녹음 | 일시 중지 및 다시 시작
- 21. 세션 일시 중지 및 다시 시작
- 22. Java 애플릿 일시 중지/다시 시작
- 23. 발리 : 일시 중지/다시 시작 다운로드
- 24. Cocos2D Director 일시 중지/다시 시작 문제
- 25. AVFoundation으로 비디오 녹화 일시 중지/다시 시작
- 26. 메서드 일시 중지 및 다시 시작
- 27. 타이머의 일시 중지/다시 시작 기능
- 28. 스윙 애니메이션 일시 중지 및 다시 시작
- 29. performSelector afterDelay를 일시 중지했다가 다시 시작 하시겠습니까?
- 30. D3 전환 - 일시 중지 및 다시 시작
는이 http://stackoverflow.com/questions/6237079/resume-http-file-download-in-java – laxonline
@laxonline 큰 감사를 참조 되세요 ! 이 질문을 답으로 게시하면 동의하고이를 닫을 수 있습니다. –