English | 中文
提交一个Issue, iOS和macOS平台使用CocoaDownloader.
Android Downloader是一个开源的多线程,多任务下载框架。
更多功能和使用方法可以查看这个APK.
在根项目的build.gradle文件中添加仓库地址:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
添加依赖:
dependencies {
implementation 'com.ixuea:android-downloader:latest'
}
如果要使用Snapshot版本, 请查看Snapshotswiki页面.
如果你的项目使用了ProGuard,你需要添加下面的配置信息到项目的proguard-rules.pro文件中
-keep public class * implements com.ixuea.android.downloader.db.DownloadDBController
更多的信息可以查看GitHub wiki和Javadocs.
<uses-permission android:name="android.permission.INTERNET" />
downloadManager = DownloadService.getDownloadManager(context.getApplicationContext());
//create download info set download uri and save path.
File targetFile = new File(getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "a.apk");
final DownloadInfo downloadInfo = new DownloadInfo.Builder().setUrl("http://example.com/a.apk")
.setPath(targetFile.getAbsolutePath())
.build();
//set download callback.
downloadInfo.setDownloadListener(new DownloadListener() {
@Override
public void onStart() {
tv_download_info.setText("Prepare downloading");
}
@Override
public void onWaited() {
tv_download_info.setText("Waiting");
bt_download_button.setText("Pause");
}
@Override
public void onPaused() {
bt_download_button.setText("Continue");
tv_download_info.setText("Paused");
}
@Override
public void onDownloading(long progress, long size) {
tv_download_info
.setText(FileUtil.formatFileSize(progress) + "/" + FileUtil
.formatFileSize(size));
bt_download_button.setText("Pause");
}
@Override
public void onRemoved() {
bt_download_button.setText("Download");
tv_download_info.setText("");
downloadInfo = null;
}
@Override
public void onDownloadSuccess() {
bt_download_button.setText("Delete");
tv_download_info.setText("Download success");
}
@Override
public void onDownloadFailed(DownloadException e) {
bt_download_button.setText("Continue");
tv_download_info.setText("Download fail:" + e.getMessage());
}
});
//submit download info to download manager.
downloadManager.download(downloadInfo);
更多信息请查看Demo.
- Android SDK: 要求最新Android SDK为API 21.
可以看到该Build文档配置开发环境:
./gradlew :app:run
你也可以在releases界面找到Demo APK.
请查看Demo项目.
Smile - @ixueadev on GitHub, Email is [email protected], See more ixuea(http://www.ixuea.com)
Android开发交流群QQ群: 702321063.