Skip to content

Latest commit

 

History

History
183 lines (131 loc) · 4.95 KB

zh.md

File metadata and controls

183 lines (131 loc) · 4.95 KB

android-downloader

English | 中文

License

提交一个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,你需要添加下面的配置信息到项目的proguard-rules.pro文件中

-keep public class * implements com.ixuea.android.downloader.db.DownloadDBController

如果使用?

更多的信息可以查看GitHub wikiJavadocs.

1.添加网络访问权限

<uses-permission android:name="android.permission.INTERNET" />

2.创建DownloadManager实例

downloadManager = DownloadService.getDownloadManager(context.getApplicationContext());

3.下载一个文件

//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.