Samsung Electronics logo

Receiving Notifications on Message Storage Changes



To create engaging applications with various messaging features, you must learn to receive notifications when messages and message folders are added, updated, or removed:

  1. Define the needed variable:
    /* Watch identifier */
    var watchId;
  2. Define the event handlers for different notifications using the MessagesChangeCallback listener interface:

    var messageChangeCallback = 
    {
       /* When messages are updated */
       messagesupdated: function(messages) 
       {
          console.log(messages.length + " message(s) updated");
       },
    
       /* When messages are added */
       messagesadded: function(messages) 
       {
          console.log(messages.length + " message(s) added");
       },
    
       /* When messages are deleted */
       messagesremoved: function(messages) 
       {
          console.log(messages.length + " message(s) removed");
       }
    };
    
  3. Register the listener to use the defined event handlers:
    watchId = msgService.messageStorage.addMessagesChangeListener(messageChangeCallback);
    
  4. To stop the notifications, use the removeChangeListener() method of the MessageStorage interface:

    msgService.messageStorage.removeChangeListener(watchId);
Note
To provide notifications for changes in specific conversations or message folders, use the applicable methods and event handlers similarly as above.