Samsung Electronics logo

Receiving Notifications on Property Value Changes

Learning how to receive notifications on property value changes is a basic application development skill:

  1. Register a SystemInfoPropertySuccessCallback event handler for the property value changes using the addPropertyValueChangeListener() method of the SystemInfo interface.

    The first parameter defines the property whose value changes you want to track, and the optional last parameter defines any thresholds when you want the notifications to be triggered. In the following example, an event handler is registered for the power property value changes, and a notification is set to be triggered when the power level decreases below 0.2.

    var id = webapis.systeminfo.addPropertyValueChangeListener("BATTERY", onSuccessCallback, 
                                                             {lowThreshold = 0.2});

    The method returns a watch identifier, which can be used to unregister the event handler.

  2. In the success event handler of the addPropertyValueChangeListener() method, define the notification event actions.

    In the following example, a warning about the low battery is logged to the console.

    /* Trigger a notification */
    function onSuccessCallback(battery) 
       console.log("Low battery: " + battery.level);
  3. To unregister the event handler, use removePropertyValueChangeListener() method with the watch identifier returned from the addPropertyValueChangeListener() method.

    In the following example, the event handler is unregistered after the first notification about the low power level has been triggered.

       if (id != null)