PRDownloader Documentation

repository·master·Indexed 25 days ago

https://github.com/amitshekhariitbhu/prdownloader

An Android library for downloading various file types, including images, videos, PDFs, and APKs. It features built-in support for pausing, resuming, and handling large files, with optional database support for resuming downloads after the application is killed.

Tokens
1.4K
Snippets
2
Records
5
Agent score
36%

What's inside PRDownloader

  1. Install PRDownloader in your Android application

    master
    To use PRDownloader, add the JitPack repository to your settings.gradle or settings.gradle.kts file, then add the dependency to your build.gradle or build.gradle.kts file. You must also ensure the INTERNET permission is declared in your AndroidManifest.xml.
  2. Initialize PRDownloader

    master

    Initialize the library in the onCreate() method of your Application class. You can use a default initialization or provide a PRDownloaderConfig to enable database support for resume functionality after the app is killed, or to set global network timeouts.

    // Default initialization
    PRDownloader.initialize(getApplicationContext());
    
    // Initialization with database enabled for resume support
    PRDownloaderConfig config = PRDownloaderConfig.newBuilder()
                    .setDatabaseEnabled(true)
                    .build();
    PRDownloader.initialize(getApplicationContext(), config);
    
    // Initialization with custom timeouts
    PRDownloaderConfig config = PRDownloaderConfig.newBuilder()
                    .setReadTimeout(30_000)
                    .setConnectTimeout(30_000)
                    .build();
    PRDownloader.initialize(getApplicationContext(), config); 
  3. Check download status and clean up files

    master
    Use PRDownloader.getStatus(downloadId) to retrieve the current Status of a specific download. If you have enabled the database for resume support, you can use PRDownloader.cleanUp(days) to remove temporary resumed files that are older than the specified number of days.
  4. Make a download request

    master

    Use PRDownloader.download(url, dirPath, fileName) to initiate a download. The method returns a downloadId which can be used to control the request later. You can attach various listeners for progress, start/resume, pause, and cancel events, and finally call .start(OnDownloadListener) to begin the process.

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