多线程断点下载框架
多线程断点下载框架--多个开源框架的组合 https://github.com/yangfuhai/afinal 使用FinalHttp下载文件:
支持断点续传,随时停止下载任务 或者 开始任务
FinalHttp fh = new FinalHttp();
//调用download方法开始下载
HttpHandler handler = fh.download("http://www.xxx.com/下载路径/xxx.apk", //这里是下载的路径
true,//true:断点续传 false:不断点续传(全新下载)
"/mnt/sdcard/testapk.apk", //这是保存到本地的路径
new AjaxCallBack() {
@Override
public void onLoading(long count, long current) {
textView.setText("下载进度:"+current+"/"+count);
}
@Override
public void onSuccess(File t) {
textView.setText(t==null?"null":t.getAbsoluteFile().toString());
}
});
//调用stop()方法停止下载
handler.stop();
|
public class MainActivity extends Activity {
private TextView tv_download;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv_download = (TextView) this.findViewById(R.id.tv_download);
}
public void download(View view) {
FinalHttp finalHttp = new FinalHttp();
String url = "http://192.168.221.221:8080/web/e.exe";
System.out.println("sdcard状态:" + Environment.getExternalStorageState());
String target = Environment.getExternalStorageDirectory() + "/e1.exe";
finalHttp.download(url, target, true, new AjaxCallBack<File>() {
@Override
public void onLoading(long count, long current) {
tv_download.setText("下载进度:" + current + "/" + count);
}
@Override
public void onSuccess(File t) {
Toast.makeText(getApplicationContext(), "下载成功", 0).show();
}
});
}
} |