npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cordova-plugin-downloadmanager-android

v1.0.0

Published

This Plugin uses the android-system download manager

Downloads

52

Readme

Androids Download-Manager

This Cordova-Plugin uses the Download-Manager of Android System. The Download ends up as a file in the default download folder and as a notification in the notification-area of the android system, while downloading and after download with the possibility to open the downloaded file.

This Plugin includes enqueueing downloads (including header support for e.g. adding authentication headers), requesting status of downloads and removing downloads.

Installation

for npm hit following command:

npm install cordova-plugin-downloadmanager-android

afterwards install the plugin

cordova plugin add cordpva-plugin-downloadmanager-android

Functions

Enqueue - queues a download to the download-manager of android system

Call following function to queue a download to the download-manager which will download the file as soon as possible: DownloadManagerAndroid.enqueue(data: EnqueueData, success: SuccessCallback, error: ErrorCallback);

The EnqueueData contains following data:

interface EnqueueData {
    url: string;
    fileName?: string;
    title?: string;
    description?: string;
    mimeType?: string;
    header?: [
        {
            header: string;
            value: string;
        }
    ]
}

The SuccessCallback is a function defined like so (id: string) => void

The ErrorCallback is a function defined like so (error: string) => void

Example

DownloadManagerAndroid.enqueue(
    {
        url: "https://google.de/big-picture.png",
        fileName: "big-picture.png",
        mimeType: "image/png",
        header: [
            {
                header: "cookie",
                value: "token=1234jkl34589kldsf83i34mejrewei4"
            }
        ]
    },
    (data) => console.log(data),
    (error) => console.log(error)
);

Query - request the status of a download

Call following function to query the status of a specific download enquede by the download-manager: DownloadManagerAndroid.query(data: QueryData, success: SuccessCallback, error: ErrorCallback);

The QueryData contains following data:

interface QueryData {
    id: string;
}

The SuccessCallback is a function defined like so (data: DownloadStatus) => void with following data response:

interface DownloadStatus {
    id: string;                     // https://developer.android.com/reference/android/app/DownloadManager#COLUMN_ID
    title: string;                  // https://developer.android.com/reference/android/app/DownloadManager#COLUMN_TITLE
    description: string;            // https://developer.android.com/reference/android/app/DownloadManager#COLUMN_DESCRIPTION
    mimeType: string;               // https://developer.android.com/reference/android/app/DownloadManager#COLUMN_MEDIA_TYPE
    localUri: string;               // https://developer.android.com/reference/android/app/DownloadManager#COLUMN_MEDIAPROVIDER_URI
    mediaProviderUri: string;       // https://developer.android.com/reference/android/app/DownloadManager#COLUMN_MEDIAPROVIDER_URI
    uri: string;                    // https://developer.android.com/reference/android/app/DownloadManager#COLUMN_URI
    lastModifiedTimestamp: string;  // https://developer.android.com/reference/android/app/DownloadManager#COLUMN_LAST_MODIFIED_TIMESTAMP
    status: string;                 // https://developer.android.com/reference/android/app/DownloadManager#COLUMN_STATUS
    reason: string;                 // https://developer.android.com/reference/android/app/DownloadManager#COLUMN_REASON
    bytesDownloadedSoFar: string;   // https://developer.android.com/reference/android/app/DownloadManager#COLUMN_BYTES_DOWNLOADED_SO_FAR
    totalSizeBytes: string;         // https://developer.android.com/reference/android/app/DownloadManager#COLUMN_TOTAL_SIZE_BYTES
}

The ErrorCallback is a function defined like so (error: string) => void

Example

DownloadManagerAndroid.query(
    {id: 51},
    (data) => console.log(data),
    (error) => console.log(error)
);

Remove - removes a download

Call following function to remove a download from download folder and notification area: DownloadManagerAndroid.remove(data: RemoveData, success: SuccessCallback, error: ErrorCallback);

The RemoveData contains following data:

interface RemoveData {
    id: string;
}

The SuccessCallback is a function defined like so (info: 'done' | 'failed') => void

The ErrorCallback is a function defined like so (error: string) => void

Example

DownloadManagerAndroid.remove(
    {id: 12},
    (data) => console.log(data),
    (error) => console.log(error)
);

Types

Using types within the namspace AndroidDownloadManger.

For Example:

const data: DownloadManagerAndroid.EnqueueData = {
    url: 'https://google.de/big-picture.png';
    fileName?: 'bigPicture.png';
}

General Development

Testing a Plugin during development

The simplest way to manually test a plugin during development is to create a Cordova app as usual and add the plugin with the --link option:

$ npm run cordova -- plugin add ../path/to/my/plugin/relative/to/project --link

This creates a symbolic link instead of copying the plugin files, which enables you to work on your plugin and then simply rebuild the app to use your changes.

For Windows

After adding the plugin to your project, you probably will need to install npm again npm i and afterwards you will remove platforms and plugins folder and add the platform again and build the app again.

to use your changes while develeping you will need to do following command:

$ rm -rf platforms plugins && npm run cordova -- platform add android && npm run cordova -- build android --packageType=apk

For Linux / Mac

Just rebuild the app

$ npm run cordova -- build android --packageType=apk

Install your App on a device using adb

$ adb install -r platforms/android/app/build/outputs/apk/debug/app-debug.apk

Debugging - Logging

For logging what is going on the device start logging with following command

adb logcat > ./log.txt https://ourcodeworld.com/articles/read/295/how-to-debug-java-code-in-a-cordova-android-application-from-your-device-using-adb-in-windows