private TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.tv);
HttpUtils http = new HttpUtils();
HttpHandler handler = http.download("http://192.168.12.23:8080/b.jpg",
"/mnt/sdcard/tom.png",
true, // 锟斤拷锟侥匡拷锟斤拷募锟斤拷锟斤拷冢锟斤拷锟斤拷锟轿达拷锟缴的诧拷锟街硷拷锟斤拷锟斤拷锟截★拷锟斤拷锟斤拷锟斤拷锟斤拷支锟斤拷RANGE时锟斤拷锟斤拷锟斤拷锟斤拷锟截★拷
true, // 锟斤拷锟斤拷锟斤拷锟襟返伙拷锟斤拷息锟叫伙拷取锟斤拷锟侥硷拷锟斤拷锟斤拷锟斤拷锟斤拷珊锟斤拷远锟斤拷锟斤拷锟斤拷锟�
new RequestCallBack<File>() {
@Override
public void onStart() {
tv.setText("姝e湪涓嬭浇");
}
@Override
public void onLoading(long total, long current, boolean isUploading) {
tv.setText(current + "/" + total);
}
@Override
public void onSuccess(ResponseInfo<File> responseInfo) {
tv.setText("涓嬭浇瀹屾垚:" + responseInfo.result.getPath());
}
@Override
public void onFailure(HttpException error, String msg) {
tv.setText("涓嬭浇澶辫触");
}
});
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.tv);
HttpUtils http = new HttpUtils();
HttpHandler handler = http.download("http://192.168.12.23:8080/b.jpg",
"/mnt/sdcard/tom.png",
true, // 锟斤拷锟侥匡拷锟斤拷募锟斤拷锟斤拷冢锟斤拷锟斤拷锟轿达拷锟缴的诧拷锟街硷拷锟斤拷锟斤拷锟截★拷锟斤拷锟斤拷锟斤拷锟斤拷支锟斤拷RANGE时锟斤拷锟斤拷锟斤拷锟斤拷锟截★拷
true, // 锟斤拷锟斤拷锟斤拷锟襟返伙拷锟斤拷息锟叫伙拷取锟斤拷锟侥硷拷锟斤拷锟斤拷锟斤拷锟斤拷珊锟斤拷远锟斤拷锟斤拷锟斤拷锟�
new RequestCallBack<File>() {
@Override
public void onStart() {
tv.setText("姝e湪涓嬭浇");
}
@Override
public void onLoading(long total, long current, boolean isUploading) {
tv.setText(current + "/" + total);
}
@Override
public void onSuccess(ResponseInfo<File> responseInfo) {
tv.setText("涓嬭浇瀹屾垚:" + responseInfo.result.getPath());
}
@Override
public void onFailure(HttpException error, String msg) {
tv.setText("涓嬭浇澶辫触");
}
});
}
注意 这个地方就是我们只需要传入下载地址以及存储地址就可以实现下载。