The Battery API is used to notify the user of the remaining power in the battery. Windows Mobile / CE devices also support displaying a small indicator to show the available power.
In order to use this API you must include the following extension in your build.yml
.
extensions: ["indicators"]
The indicators
extension is also included automatically if you specify the following in your build.yml
app_type: "rhoelements"
If you are building a Windows Mobile or Windows CE app with this API, you must set your app_type as “rhoelements” in your build.yml as shown in this build-time settings example. |
Be sure to review the JavaScript API Usage guide for important information about using this API in JavaScript.
Be sure to review the Ruby API Usage guide for important information about using this API in Ruby.
Retrieve the current battery level. If a callback is provided to retrieve the battery then it will be called periodically at a frequency determined by the trigger property.
Parameters
The properties associated with accessing the battery status.
What will cause the batteryStatus callback to fire. It is recommended to use system events to conserve battery life. Please note, that iOS devices have no system triggers and will provide updates only with a specified period (Trigger value will be ignored)
Possible Values :
The batteryStatus callback will fire periodically at the specified refresh interval. This is the default setting on Windows Mobile / CE / Embedded but those platforms do also support the system trigger. Not supported on Android.
The batteryStatus callback will fire when the underlying operating system notifies that there has been a change to the battery level. The resolution of this change will vary depending on operating system, for example on WP8 you are notified every percentage value change but on Windows Mobile the notifications only occur when ‘critical’, ‘full’ etc.
Alternative way of specifying the refreshInterval parameter. If you are using a system trigger then this parameter will be ignored.
Async Callback Returning Parameters: HASH
Whether or not the device is connected to external power.
The remaining battery power as a value between 0 and 100.
The remaining backup battery power as a percentage between 0 and 100. Only supported on Zebra Windows Mobile / CE / Embedded devices.
Platforms:WMHuman readable form of what has caused this callback to fire. This value will be OS dependent. On Windows Mobile / CE / Embedded it will be one of: “High Battery”, “Low Battery”, “Critical Battery”, “Charging”, “No Battery”, “Unknown”. In the case of periodic updates, this field will contain the last known status of the battery.
Platforms:WM, AndroidOnly supported on Zebra Technologies' Windows Mobile / CE / Embedded devices. The battery life will not be readable for a period of time after removing from an AC power source and this parameter will state whether the batteryLifePercent value is accurate.
Platforms:WMOnly supported on Zebra Technologies' Windows Mobile / CE / Embedded devices. The battery life will not be readable for a period of time after removing from an AC power source and this parameter will state whether the backupBatteryLifePercent value is accurate.
Platforms:WMSynchronous Return:
Whether or not the device is connected to external power.
The remaining battery power as a value between 0 and 100.
The remaining backup battery power as a percentage between 0 and 100. Only supported on Zebra Windows Mobile / CE / Embedded devices.
Platforms:WMHuman readable form of what has caused this callback to fire. This value will be OS dependent. On Windows Mobile / CE / Embedded it will be one of: “High Battery”, “Low Battery”, “Critical Battery”, “Charging”, “No Battery”, “Unknown”. In the case of periodic updates, this field will contain the last known status of the battery.
Platforms:WM, AndroidOnly supported on Zebra Technologies' Windows Mobile / CE / Embedded devices. The battery life will not be readable for a period of time after removing from an AC power source and this parameter will state whether the batteryLifePercent value is accurate.
Platforms:WMOnly supported on Zebra Technologies' Windows Mobile / CE / Embedded devices. The battery life will not be readable for a period of time after removing from an AC power source and this parameter will state whether the backupBatteryLifePercent value is accurate.
Platforms:WMMethod Access:
Rho.Battery.batteryStatus(HASH propertyMap, CallBackHandler callback)
Rho::Battery.batteryStatus(HASH propertyMap, CallBackHandler callback)
Hide the icon if it has been previously set by the ‘showIcon’ call.
(All platforms support batteryStatus which can be used to draw your own level indicator or display an appropriate graphic.)
Synchronous Return:
Method Access:
Rho.Battery.hideIcon()
Rho::Battery.hideIcon()
Overlays a small battery icon on top of the view indicating the remaining battery strength. This is particularly useful in full screen applications which cover the system battery level indicator.
(All platforms support batteryStatus which can be used to draw your own level indicator or display an appropriate graphic.)
Parameters
The properties associated with the indicator, its position and color.
The absolute horizontal position of the indicator in pixels. This value is relative to the screen and not the view, so non-fullscreen applications should take care not to display the indicator off screen.
The absolute vertical position of the indicator in pixels. Positive numbers go towards the bottom of the screen. This value is relative to the screen and not the view, so non-fullscreen applications should take care not to display the indicator off screen.
Sets the orientation of the icon, see the remarks section for illustrations.
Possible Values :
See the remarks section for illustrations of icon layout.
See the remarks section for illustrations of icon layout.
See the remarks section for illustrations of icon layout.
See the remarks section for illustrations of icon layout.
The color of the icon. This value must be specified as a Hex value in the format #000000 to #FFFFFF. Alpha values are not supported, i.e. You can only use the component parts RRGGBB.
Synchronous Return:
Method Access:
Rho.Battery.showIcon(HASH propertyMap)
Rho::Battery.showIcon(HASH propertyMap)
Returns the various parameters relating to battery charge and battery hardware. Not all return values may be supported by all batteries.
(Scanners on Zebra Technologies' Windows Mobile / CE / Embedded devices)
Parameters
Async Callback Returning Parameters: HASH
The serial number of the battery.
The Zebra Technologies' part number of the battery, e.g. 21-65587 Rev. A.
The number of times the battery has been charged. Partial charges are aggregated, therefore each charge cycle count represents one full charge / discharge cycle. The battery charge cycle count gets updated when the battery charging state changes from charging to not charging. Cycle count may not accurately predict the life of a battery.
Rated capacity of the battery in mAh.
Date the battery was manufactured expressed as MM/DD/YYYY.
The health of the battery.
Possible Values :
The battery is healthy.
The battery is unhealthy.
The battery health is unknown.
Synchronous Return:
The serial number of the battery.
The Zebra Technologies' part number of the battery, e.g. 21-65587 Rev. A.
The number of times the battery has been charged. Partial charges are aggregated, therefore each charge cycle count represents one full charge / discharge cycle. The battery charge cycle count gets updated when the battery charging state changes from charging to not charging. Cycle count may not accurately predict the life of a battery.
Rated capacity of the battery in mAh.
Date the battery was manufactured expressed as MM/DD/YYYY.
The health of the battery.
Possible Values :
The battery is healthy.
The battery is unhealthy.
The battery health is unknown.
Method Access:
Rho.Battery.smartBatteryStatus(CallBackHandler callback)
Rho::Battery.smartBatteryStatus(CallBackHandler callback)
If the battery status is being retrieved via callback, by a previously invoked call to batteryStatus, this method will stop the callback from firing.
Synchronous Return:
Method Access:
Rho.Battery.stopBatteryStatus()
Rho::Battery.stopBatteryStatus()
A callback to retrieve the battery strength can be specified to occur periodically with the batteryStatus method. This value specifies the periodicity of the callback as well as the update frequency of the battery icon, if shown. Note that most platforms will not support periodic updates to the battery level, this is only supported on Windows Mobile / CE / Embedded.
Default: 5000
Property Access:
Rho.Battery.refreshInterval
Rho::Battery.refreshInterval
Synchronously: If you are only interested in the current battery level, for example to decide whether you have sufficient battery for the worker to start their shift, then you can immediately determine the level as follows
function battery_status_sync(){ batteryValues = Rho.Battery.batteryStatus({}); console.log("Battery Level is: " + batteryValues['batteryLifePercent']); }
def battery_status_sync batteryValues = Rho::Battery.batteryStatus puts "Battery Level is: " + batteryValues['batteryLifePercent'] end
Asynchronously: If you want to be notified of changes to the battery levelthen you can register to receive values through a callback
function battery_status_async(){ console.log("Registering Battery Callback"); Rho.Battery.batteryStatus({},batteryEvent); } function batteryEvent(params){ console.log("Battery Event Fired:"); console.log("Battery Event (Asynchronous). AC Line Status: " + params["acLineStatus"] + " Battery Life Percent: " + params["batteryLifePercent"] + " Backup Battery Life Percent: " + params["backupBatteryLifePercent"] + " Status: " + params["batteryStatus"] + " Battery Life Known: " + params["batteryLifeKnown"] + " Backup Battery Life Known: " + params["backupBatteryLifeKnown"]); }
def battery_status_async puts "Registering Battery Callback" Rho::Battery.batteryStatus(url_for(:action => :batteryEvent)) end def batteryEvent puts "Battery Event Fired: #{@params}" puts "Battery Event (Asynchronous). AC Line Status: #{@params["acLineStatus"]}, Battery Life Percent: #{@params["batteryLifePercent"]}, Backup Battery Life Percent: #{@params["backupBatteryLifePercent"]}, Status: #{@params["batteryStatus"]}, Battery Life Known: #{@params["batteryLifeKnown"]}, Backup Battery Life Known: #{@params["backupBatteryLifeKnown"]}" end
If you just want to display the battery indicator in the default position and default color then call as follows.
function show_battery_icon(){ Rho.Battery.showIcon({}); }
def show_battery_icon Rho::Battery.showIcon({}) end
To display the battery icon at the default position but blue and vertical specify as follows.
function show_battery_icon(){ Rho.Battery.showIcon({ left: 0, top: 40, color: '#FF0000', layout: Rho.Battery.BATTERY_LAYOUT_RIGHT }); }
def show_battery_icon Rho::Battery.showIcon { left: 0, top: 40, color: '#FF0000', layout: Rho::Battery.BATTERY_LAYOUT_RIGHT }
The position of the signal and battery indicators should not be set to overlap
The indicator positions are absolute and so when rotating the screen you should also move the indicator positions accordingly to accommodate the new screen layout.