首先感谢网上的大神,我是参考大神代码再自己封装的
功能:下载文件到 SD卡中 实现断点续传已经封装好
下载链接在最后
示例代码:
构造函数
参数(content,url下载地址,线程数量,存放路径,存放文件名)
如果文件名为NULL将为网络上下载的默认名字
File file=new File(dowloadDir);//下载路径
Ydownload ydownload=new Ydownload(context, URL, 10, filepath, fileName);
开始下载
ydownload.start();
停止下载
ydownload.stop();
回调
ydownload.setDownloadProgressListener(new DownloadProgressListener() {
@Override
public void onDownloadSize(int size, int fileSize) {
Message msg = new Message();// Handler通知前台
msg.what = 0;//
Object[] obj = { fileSize, size ,size*100/fileSize};//总大小,当前大小,当前百分比
msg.obj = obj;
mHandler2.sendMessage(msg);
}
@Override
public void failure(String error) {
}
});
判断SD卡方法
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
} else {
Log.e("", "没有SD卡");
}
下载链接:下载地址