Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.planitian:tigerdownload:1.1.9'
}
dependencies {
implementation("com.github.planitian:tigerdownload:1.1.9")
}
<dependency>
<groupId>com.github.planitian</groupId>
<artifactId>tigerdownload</artifactId>
<version>1.1.9</version>
</dependency>
libraryDependencies += "com.github.planitian" % "tigerdownload" % "1.1.9"
:dependencies [[com.github.planitian/tigerdownload "1.1.9"]]
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.planitian:TigerDownload:1.1.5'
}
//下载链接
String url = "https://uu.gdl.netease.com/2183/UU-2.10.5.exe";
//文件保存目录
String savePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + Environment.DIRECTORY_DOWNLOADS;
TaskInfo downLoadBean = new TaskInfo.Builder(url, savePath)
//注册观察者
.registerObserver(new DownloadObserver() {
//taskinfo 携带着下载的信息,如已经读取的字节数,总文件长度(如果,http返回了 文件长度)
//下载状态@Link{ DownloadState } @Override
public void update(TaskInfo downLoadBean) {
if (downLoadBean.getContentLength() != 0) {
int progress = (int) (100 * downLoadBean.getReadLength() / downLoadBean.getContentLength());
/*
1. 注意 这里只有配置了 runMain(true) 才可以直接更新ui,否则报异常 * */ progressBar.setProgress(progress);
/* runOnUiThread(new Runnable() {
@Override public void run() {
} });*/ }
}
}).runMain(true).build();
//必须先addTask,然后才可以 startTask
DownLoadManager.getInstance().addTask(downLoadBean).startTask(downLoadBean);