Samsung Electronics logo

Monitoring the Call History

Learning how to register change listeners allows you to synchronize the view of your application to changes in the call history database.

  1. Use the addChangeListener() method of the CallHistory interface to register a listener for observing call history changes:

    var callHistoryListener = webapis.callhistory.addChangeListener(onHistoryChange);
  2. Define the onadded event handler of the CallHistoryChangeCallback listener interface, which tracks all new incoming and outgoing calls that are added to the call history.

    var onHistoryChange = 
       onadded: function(newItems)
          output.append('New item added');
          for (var i in newItems)
             output.append('Item ' + i + 'startTime: ' + newItems[i].startTime);
  3. Define the onchanged event handler, which tracks all changes in the call history.

    The event handler receives as an argument an array of CallHistoryEntry instances, which represent the changed items in the call history.

       onchanged: function(changedItems)
          output.append('Items changed');
          for (var i in changedItems)
             output.append('Item ' + i + 'direction: ' + changedItems[i].direction);
  4. Use the removeChangeListener() method to unregister a previously registered listener. Use the ID returned by the addChangeListener():