Samsung Electronics logo

Retrieving the Current State of a Property



Learning how to retrieve information about the property states is a basic application development skill:

  1. To check the current state of the property, use the getPropertyValue() method.

    The first method parameter must be of the PropertyId type (for the available values, see the Available properties table).

    /* Retrieve the battery property */
    webapis.systeminfo.getPropertyValue("BATTERY", onPowerSuccessCallback);
    
    

    After retrieving a property, you can use all the details of the property in your code. The property values are returned in the success event handlers defined below.

  2. Use the power property values.

    In the following example, the battery level and charging status of the power property are printed to a console log.

    function onPowerSuccessCallback(battery) 
    {
       /* Log the device battery level to the console */
       console.log("The battery level is " + battery.level);
    
       /* Check whether the device is charging */
       var charging = battery.isCharging;
    
       if (charging)
       {
          /* Display the charging info */
          console.log("Device is charging");
       }
    }