HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(downloadurl);
HttpResponse response;
try {
response = client.execute(get);
HttpEntity entity = response.getEntity();
long length = entity.getContentLength();
InputStream is = entity.getContent();
FileOutputStream fileOutputStream = null;
if (is != null) {
File file = new File(Environment
.getExternalStorageDirectory(),
fileName);
fileOutputStream = new FileOutputStream(file);
byte[] buf = new byte[1024];
int ch = -1;
int count = 0;
int percent = 0;
while ((ch = is.read(buf)) != -1) {
fileOutputStream.write(buf, 0, ch);
count += ch;
if (((int) (100 * count / length)) > percent) {
percent = (int) (100 * count / length);
progressDialog.setProgress(percent);
if (percent == 100) {
successDownload = true;
}
}
if (length > 0) {
}
}
}
fileOutputStream.flush();
if (fileOutputStream != null) {
fileOutputStream.close();
}
down(fileName);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
progressDialog.cancel();
}
之前的下载地址是文件路径,可以下载,后来改成我给后台发请求后下载,这样下载就不行了,这个应该怎么改?