• Stars
    star
    409
  • Rank 105,709 (Top 3 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created over 11 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Access and modify badge numbers

SAMPLE APP 👉

Cordova Badge Plugin
npm version Code Climate PayPayl donate button

Cordova plugin to access and modify the badge number of the app icon on various mobile platforms including iOS, Android and Windows.

How they appear to the user

Users see notifications in the following ways:

Supported Platforms

Installation

The plugin can be installed via Cordova-CLI and is publicly available on NPM.

Execute from the projects root folder:

$ cordova plugin add cordova-plugin-badge

Or install a specific version:

$ cordova plugin add cordova-plugin-badge@VERSION

Or install the latest head version:

$ cordova plugin add https://github.com/katzer/cordova-plugin-badge.git

Or install from local source:

$ cordova plugin add <path> --nofetch --nosave

Usage

The plugin creates the object cordova.plugins.notification.badge and is accessible after deviceready has been fired.

document.addEventListener('deviceready', function () {
    // cordova.plugins.notification.badge is now available
}, false);

Set the badge number

Badge numbers cannot be negative. The maximum might be restricted by the OS. A callback is optional and will be invoked with the current badge number.

cordova.plugins.notification.badge.set(10);

         

There's built-in support to increase the badge number:

cordova.plugins.notification.badge.increase(1, function (badge) {
    // badge is now 11 (10 + 1)
});

To decrease the badge number:

cordova.plugins.notification.badge.decrease(2, function (badge) {
    // badge is now 9 (11 - 2)
});

And to clear out the badge number:

cordova.plugins.notification.badge.clear();

Get the badge number

The default value is 0. The badge number wont get lost after reboot or app restart.

cordova.plugins.notification.badge.get(function (badge) {
    ...
});

Note: Modifying the badge number outside of the plugin does result into wrong behaivor!

Configurations

To clear the badge number automatically if the user taps the app icon:

cordova.plugins.notification.badge.configure({ autoClear: true });

OSX supports additional indicators. Other than to badge these are circular and download.

cordova.plugins.notification.badge.configure({ indicator: 'circular' });

         

Permissions

The plugin might ask for granting permissions to modify the badge number. That's done automatically but it's also possible to request them manually:

cordova.plugins.notification.badge.requestPermission(function (granted) {
    ...
});

To check if they have been granted already:

cordova.plugins.notification.badge.hasPermission(function (granted) {
    ...
});

Quirks

On Android not all launchers support badges. In order to set badges the plugin uses ShortcutBadger. Check out their website to see which launchers are supported.

If you're using PhoneGap Build please make sure you specify gradle as your Android build tool in config.xml:

<preference name="android-build-tool" value="gradle" />

To specify a custom version of ShortcutBadger follow this guide. The name of the property is appShortcutBadgerVersion.

# In <your-project>/platforms/android/gradle.properties
appShortcutBadgerVersion=1.1.22

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

This software is released under the Apache 2.0 License.

Made with 😋 from Leipzig

© 2013 appPlant GmbH

More Repositories

1

cordova-plugin-local-notifications

Cordova Local-Notification Plugin
Java
2,561
star
2

cordova-plugin-background-mode

Keep app running in background
Java
1,382
star
3

cordova-plugin-email-composer

Edit and send email messages
Objective-C
344
star
4

cordova-plugin-printer

Print HTML documents
Objective-C
312
star
5

mruby-yeah

mruby on tiny rails
Ruby
40
star
6

cordova-plugin-hidden-statusbar-overlay

Cordova plugin to hide the statusbar and overlay on iOS
Objective-C
27
star
7

cordova-plugin-app-event

Cordova App-Event Plugin
Objective-C
26
star
8

mruby-shelf

Modular webserver interface for mruby
Ruby
24
star
9

mruby-r3

mruby bindings for libr3
C
15
star
10

mruby-logger

A simple but sophisticated logging utility that you can use to output messages
Ruby
7
star
11

mruby-os

Determine system and binary capabilities at runtime
Ruby
6
star
12

mruby-terminal-table

mruby table generator
Ruby
6
star
13

mruby-ssh

SSH client for mruby
Ruby
6
star
14

mruby-tiny-opt-parser

Command-line option analysis for mruby
Ruby
3
star
15

mruby-heeler

multi-process web server for shelf
Ruby
2
star
16

ski

Sascha Knows It
Ruby
1
star
17

mrubycross

Docker images to cross compile mruby
1
star
18

mruby-unicode-display_width

Monospace Unicode character width in mruby
C
1
star
19

mruby-sftp

SFTP client for mruby
Ruby
1
star
20

mruby-sftp-glob

SFTP::Dir#glob extension for mruby-sftp
Ruby
1
star
21

hidemyass2

Hide My Ass! /2 fetches proxies at www.hidemyass.com
Ruby
1
star
22

docker-images

Docker images for mruby-cli based binaries
1
star
23

senchatouch-windowsphone-fontface

@font-face replacement for Sencha Touch on Windows Phone
CSS
1
star
24

cordova-common-registerusernotificationsettings

Implements didRegisterUserNotificationSettings and broadcasts the event
Objective-C
1
star
25

iss

API endpoint for Orbit
Ruby
1
star
26

mruby-shelf-deflater

Shelf middleware enables compression of http responses.
Ruby
1
star