DownloadManager是系统提供的下载组件
最简单的用法:
//创建下载任务,downloadUrl就是下载链接
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(downloadUrl));
//指定下载路径和下载文件名
request.setDestinationInExternalPublicDir("/download/", fileName);
//获取下载管理器
DownloadManager downloadManager= (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);
//将下载任务加入下载队列,否则不会进行下载
downloadManager.enqueue(request);
有三个相关的类
DownloadManager
DownloadManager.Request
DownloadManager.Query
可自定义的一些设置: