PRDownloader

amitshekhariitbhuApache-2.0更新放缓

Android 上的文件下载库,支持断点续传和暂停恢复,适合下载大文件时避免中断重来。

PRDownloader - A file downloader library for Android with pause and resume support

1.0.2发布于 2025-03-05 15:06 UTC3,395star543fork同步于 2026-11-10 23:41 UTC

怎么上手

由 README 提炼,执行前请确认
在 settings.gradle 添加 maven { url 'https://jitpack.io' },在 build.gradle 添加 implementation 'com.github.amitshekhariitbhu:PRDownloader:1.0.2'
硬件要求按 README 说明

README 未说明

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

Android 文件下载库,支持暂停与断点续传,适合在 App 内下载大文件

Android 上的文件下载库,支持断点续传和暂停恢复,适合下载大文件时避免中断重来。

核心能力

  • 支持暂停、恢复与取消下载请求
  • 通过 downloadId 查询下载状态
  • 提供 onProgress、onStart、onError 等回调
  • 可并行发起多个下载请求
  • 可开启数据库以在应用被杀后仍能续传

容易踩的坑

需在 AndroidManifest 中自行添加 INTERNET 权限;需在 Application 的 onCreate 中调用 PRDownloader.initialize 初始化;应用被杀后仍要续传需在配置中开启 setDatabaseEnabled(true)

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本1.0.2
  1. 1.0.2Release 1.0.2最新正式版2025-03-05 · 2025-03-05 15:06 UTC

    这个版本没有写更新说明。

  2. 1.0.1Release 1.0.12024-08-18 · 2024-08-18 15:37 UTC

    这个版本没有写更新说明。

  3. 0.7.0Jitpack 0.7.02024-08-18 · 2024-08-18 15:17 UTC

    这个版本没有写更新说明。

  4. v0.6.0Fix for server error message2019-06-13 · 2019-06-13 06:21 UTC
    查看更新说明

    Merge fix for the server error message

  5. v0.5.0Fix for release mode proguard2018-12-12 · 2018-12-12 11:23 UTC
    查看更新说明
    • Merge fix for release mode issue

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    PRDownloader - A file downloader library for Android with pause and resume support

    Sample Download

    <img src=https://raw.githubusercontent.com/amitshekhariitbhu/PRDownloader/master/assets/sample_download.png width=360 height=640 />

    Overview of PRDownloader library

    • PRDownloader can be used to download any type of files like image, video, pdf, apk and etc.
    • This file downloader library supports pause and resume while downloading a file.
    • Supports large file download.
    • This downloader library has a simple interface to make download request.
    • We can check if the status of downloading with the given download Id.
    • PRDownloader gives callbacks for everything like onProgress, onCancel, onStart, onError and etc while downloading a file.
    • Supports proper request canceling.
    • Many requests can be made in parallel.
    • All types of customization are possible.

    About me

    Hi, I am Amit Shekhar, Founder @ Outcome School • IIT 2010-14 • I have taught and mentored many developers, and their efforts landed them high-paying tech jobs, helped many tech companies in solving their unique problems, and created many open-source libraries being used by top companies. I am passionate about sharing knowledge through open-source, blogs, and videos.

    Follow Amit Shekhar

    Follow Outcome School

    I teach at Outcome School

    • AI and Machine Learning
    • Android

    Join Outcome School and get a high-paying tech job: Outcome School

    Using PRDownloader Library in your Android application

    Add this in your settings.gradle:

    maven { url 'https://jitpack.io' }
    

    If you are using settings.gradle.kts, add the following:

    maven { setUrl("https://jitpack.io") }
    

    Add this in your build.gradle

    implementation 'com.github.amitshekhariitbhu:PRDownloader:1.0.2'
    

    If you are using build.gradle.kts, add the following:

    implementation("com.github.amitshekhariitbhu:PRDownloader:1.0.2")
    

    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); 
    

    Make a download request

    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) {
                                   
                                }
                            });            
    

    Pause a download request

    PRDownloader.pause(downloadId);
    

    Resume a download request

    PRDownloader.resume(downloadId);
    

    Cancel a download request

    // 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 of a download request

    Status status = PRDownloader.getStatus(downloadId);
    

    Clean up resumed files if database enabled

    // Method to clean up temporary resumed files which is older than the given day
    PRDownloader.cleanUp(days);
    

    TODO

    • Integration with other libraries like OkHttp, RxJava
    • Test Cases
    • And of course many many features and bug fixes

    Outcome School Blog - High-quality content to learn Android concepts.

    If this library helps you in anyway, show your love :heart: by putting a :star: on this project :v:

    License

       Copyright (C) 2024 Amit Shekhar
    
       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.
    

    Contributing to PRDownloader

    All pull requests are welcome, make sure to follow the contribution guidelines when you submit pull request.