Add this in your build.gradle
implementation 'com.mindorks.android:prdownloader:0.6.0'
Do not forget to add internet permission in manifest if already not present
<uses-permission android:name="android.permission.INTERNET" />
Then initialize it in onCreate() Method of application class :
PRDownloader.initialize(getApplicationContext());
Initializing it with some customization
// Enabling database for resume support even after the application is killed:
PRDownloaderConfig config = PRDownloaderConfig.newBuilder()
.setDatabaseEnabled(true)
.build();
PRDownloader.initialize(getApplicationContext(), config);
// Setting timeout globally for the download network requests:
PRDownloaderConfig config = PRDownloaderConfig.newBuilder()
.setReadTimeout(30_000)
.setConnectTimeout(30_000)
.build();
PRDownloader.initialize(getApplicationContext(), config);
int downloadId = PRDownloader.download(url, dirPath, fileName)
.build()
.setOnStartOrResumeListener(new OnStartOrResumeListener() {
@Override
public void onStartOrResume() {
}
})
.setOnPauseListener(new OnPauseListener() {
@Override
public void onPause() {
}
})
.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel() {
}
})
.setOnProgressListener(new OnProgressListener() {
@Override
public void onProgress(Progress progress) {
}
})
.start(new OnDownloadListener() {
@Override
public void onDownloadComplete() {
}
@Override
public void onError(Error error) {
}
});
PRDownloader.pause(downloadId);
PRDownloader.resume(downloadId);
// Cancel with the download id
PRDownloader.cancel(downloadId);
// The tag can be set to any request and then can be used to cancel the request
PRDownloader.cancel(TAG);
// Cancel all the requests
PRDownloader.cancelAll();
Status status = PRDownloader.getStatus(downloadId);
// Method to clean up temporary resumed files which is older than the given day
PRDownloader.cleanUp(days);
Check out Mindorks awesome open source projects here
Copyright (C) 2017 MINDORKS NEXTGEN PRIVATE LIMITED
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
All pull requests are welcome, make sure to follow the contribution guidelineswhen you submit pull request.
文章出处:https://www.jianshu.com/p/3cf8b31f3a11 安卓文件下载库 | PRDownloader 96 两只黄鹂鸣翠鸟 关注 2017.12.05 11:05 字数 171 阅读 852评论 0喜欢 4 名称 PRDownloader 语言 Android 平台 GitHub 作者 MindorksOpenSource 链接 点此进入 今天推荐的是一款具备完善功
PRDownloader 配置 implementation 'com.mindorks.android:prdownloader:0.6.0' 权限 //静态权限 <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permissi