Samsung Electronics logo

Receiving Notifications on Calendar Changes



To create engaging applications with various calendar features, you must learn to receive notifications when calendar items are added, updated, or removed:

  1. Define the needed variables:

    /* Watcher identifier */
    var watcherId = 0;
    
    /* This example assumes that the calendar is initialized */
    var calendar;
    
  2. Define the event handlers for different notifications using the CalendarChangeCallback listener interface:

    var watcher = 
    {
       /* When new items are added */
       onitemsadded: function(items) 
       {
          console.log(items.length + " items were added");
       },
    
       /* When items are updated */
       onitemsupdated: function(items) 
       {
          console.log(items.length + " items were updated");
       },
     
       /* When items are deleted */
       onitemsremoved: function(ids) 
       {
          console.log(ids.length + " items were removed");
       }
    };
    
  3. Register the listener to use the defined event handlers:

    watcherId = calendar.addChangeListener(watcher);
    
  4. To stop the notifications, use the removeChangeListener() method:

    function cancelWatch() 
    {
       calendar.removeChangeListener(watcherId);
    }