Wearable Web

Badge

A badge is a number shown in the top right corner of the application icon indicating that the application has new unread information waiting for the user. You can access the badge management functionality using the Badge API.

The main features of the Badge API include:

Managing the Badge Number

Learning how to set and retrieve badge numbers is a basic badge management skill:

  • To set the badge number for a specific application, use the setBadgeCount() method:
    Note
    You can only set the badge number of those applications that are signed with the same author certificate as your own application.
    webapis.badge.setBadgeCount("AVbg1ZHu6l.BadgeSample", 3);
    
  • To get the current badge number of a specific application, use the getBadgeCount() method:
    var count = webapis.badge.getBadgeCount("AVbg1ZHu6l.BadgeSample");
    

Monitoring Badge Number Changes

Learning how to synchronize your application view to show the changes in the badge database is a basic badge management skill:

  1. Define the applications whose badge changes you want to monitor by creating an array of application IDs:
    var appIdList = ["AVbg1ZHu6l.BadgeSample", "BDb5tZJe47.TestSample"];
    
  2. Use the addChangeListener() method of the BadgeManager interface to register a badge change listener:
    webapis.badge.addChangeListener(appIdList, onBadgeChange);
    
  3. Define the event handler for the BadgeChangeCallback interface.

    The event handler is triggered when the badge number changes, and it receives as parameters the application ID of the related application and the changed badge count.

    function onBadgeChange(appId, count) 
    {
       console.log("Badge number were updated. appId: " + appId + " count: " + count);
    }
    
  4. When you no longer need the listener, unregister it with the removeChangeListener() method. In the parameter, use the same application ID array as you used when registering the listener.
    webapis.badge.removeChangeListener(appIdList);
    
Go to top