0
이름과 URL을 전달하여 파일을 다운로드하는 기능이 필요하므로 안드로이드 앱에 일련의 파일을 다운로드 할 수 있습니다. 안드로이드 다운로드 파일 시리즈가 작동하지 않습니다
그래서 나서서 이런 식으로 뭔가를 만들어 :public void doDownload (String fileName, String url){
File root = android.os.Environment.getExternalStorageDirectory();
File dir = new File (root.getAbsolutePath() + "/Content/");
if(dir.exists()==false) {
dir.mkdirs();
}
try{
URL url = new URL(url);
URLConnection connection = url.openConnection();
connection.connect();
// this will be useful so that you can show a typical 0-100% progress bar
int fileLength = connection.getContentLength();
Log.i("ANDRO_ASYNC", "Lenght of file: " + fileLength);
// download the file
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(dir + fileName);
byte data[] = new byte[1024];
long total = 0;
int count;
while ((count = input.read(data)) != -1) {
total += count;
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
}catch(Exception e){
}
}
XML : 추가 허가
지금은이 함수를 호출 할 때 :
doDownload(String img.png, String http://server.com);
그것은 어떤 파일을 반환합니다. 여기에 무슨 문제가 있습니까?
현재 두 개 이상의 파일을 다운로드하려면 루프 내부에서 doDownload 메소드를 호출하고 있습니까? –
사용자가 옵션 1을 선택하면 옵션 1보다 url 및 name 파일이 doDownload (url, filename)로 실행되어 sdcard에 파일을 다운로드하고 저장하는 등의 방법으로이 메소드를 호출 할 수 없습니다. – star18bit
비슷한 질문이 있습니다. http://stackoverflow.com/questions/3028306/download-a-file-with-android-and-showing-the-progress-in-a-progressdialog – GrIsHu