Functions
The Battery API contains the following functions, which belong to the voltmx.os Namespace.
voltmx.os.getBatteryLevel
Retrieves the current percentage charge level of the device battery, as an integer value.
Syntax
Input Parameters
None
Example
Return Values
Returns an integer that ranges from 0-100 (inclusive) that specifies the battery’s current charge level in percentage. For example, a return value of 30 specifies that the current charge level of the battery is 30%.
Platform Availability
- iOS
- Android
- Windows
voltmx.os.getBatteryState
Retrieves the current state of the battery.
Syntax
Input Parameters
None
Example
Return Values
Returns a constant from the Battery State Constants.
Remarks
The battery state indicates whether it is charging, discharging, and so forth.
Platform Availability
- iOS
- Android
- Windows
voltmx.os.registerBatteryService
Registers for the battery monitoring service of the device operating system. The callback is delivered to the most recent registered battery service.
Note: Whenever the battery state changes or for every 1% change in the battery level, a callback to the registerBatteryService function is triggered.
Syntax
Input Parameters
Parameter | Description |
---|---|
callbackMethod | A JavaScript function that is automatically invoked when you register to the battery monitoring service of the device OS. |
Example
Return Values
None
Limitations
- The callback for the registered battery service is delivered only when the application is running; this is because, you can only receive notifications when the application is in the foreground for the iOS, Windows, and Android platforms.
- The callback to the registered battery service is delivered after every one minute duration for iOS; whereas in case of in Android and Windows, the callback is delivered for every 1% change in the battery charge.
Platform Availability
- iOS
- Android
- Windows
voltmx.os.unregisterBatteryService
This API stops the monitoring process of the device battery. You must call this API when the use of the battery monitoring service has been completed, to reduce the overhead.
Note: After your app calls the voltmx.os.unregisterBatteryService API, the callback function registered by the voltmx.os.registerBatteryService API is no longer invoked.
Syntax
Input Parameters
None
Example
Return Values
None
Platform Availability
- iOS
- Android
- Windows