file-downloader(https://github.com/wlfcolin/file-downloader)是本人开源的一个Http文件下载框架,是根据自己的经验总结的一套简非常轻量级的安卓通用Http文件下载管理器。
特点:支持断点续传、多任务下载、重命名、移动、删除、自定义下载名称和保存路径等
file-downloader采用了跟安卓图片加载框架image-loader类似的设计架构,以下是使用说明和截图:
1、在你的Application的onCreate()方法中初始化FileDownloadManager
// 1.create FileDownloadConfiguration.BuilderBuilder builder = new FileDownloadConfiguration.Builder(this);// 2.builder FileDownloadConfiguration.Builderbuilder.configFileDownloadDir(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "FileDownloader");// config the download pathbuilder.configDownloadTaskSize(3);// allow 3 download task at the same timeFileDownloadConfiguration configuration = builder.build();// config FileDownloadConfiguration with the builder// 3.init FileDownloadManager with the configurationFileDownloadManager.getInstance(this).init(configuration);
2、创建一个新下载
mFileDownloadManager.start(url, mOnFileDownloadStatusListener);
3、创建一个自定义保存文件名称和存储路径的下载
mFileDownloadManager.detect(url, new OnDetectUrlFileListener() { @Override public void onDetectNewDownloadFile(String url, String fileName, String saveDir, int fileSize) { // change fileName,saveDir if needed mFileDownloadManager.createAndStart(url, newFileDir, newFileName, mOnFileDownloadStatusListener); } @Override public void onDetectUrlFileExist(String url) { mFileDownloadManager.start(url, mOnFileDownloadStatusListener); } @Override public void onDetectUrlFileFailed(String url, DetectUrlFileFailReason failReason) { // error }});
4、继续一个已经暂停的下载
mFileDownloadManager.start(url, mOnFileDownloadStatusListener);
5、删除下载
5-1、删除单个
mFileDownloadManager.delete(url, true, mOnDeleteDownloadFileListener);// single file
5-2、删除多个
mFileDownloadManager.delete(urls, true, mOnDeleteDownloadFilesListener);// multi files
6、移动下载文件到新文件夹
6-1、移动单个
mFileDownloadManager.move(url, newDirPath, mOnMoveDownloadFileListener);// single file
6-2、移动多个
mFileDownloadManager.move(urls, newDirPath, mOnMoveDownloadFilesListener);// multi files
7、重命名下载文件
mFileDownloadManager.rename(url, newName, true, mOnRenameDownloadFileListener);
----------------end----------------
时间: 2024-10-05 00:09:00