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"
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 concerve 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 :
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 value between 0 and 100. Only supported on Zebra Windows Mobile / CE / Embedded devices. Platforms:WM
Human readable form of what has caused this callback to fire. This value will be OS dependant. 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, Android
Only 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:WM
Only 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:WM
Synchronous 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 value between 0 and 100. Only supported on Zebra Windows Mobile / CE / Embedded devices. Platforms:WM
Human readable form of what has caused this callback to fire. This value will be OS dependant. 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, Android
Only 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:WM
Only 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:WM
Method 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 :
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 accuratley 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 :
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 accuratley 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 :
Method Access:
Rho.Battery.smartBatteryStatus(CallBackHandler callback)
Rho::Battery.smartBatteryStatus(CallBackHandler callback)
If the battery 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()
Default: 5000
Property Access:
Rho.Battery.refreshInterval
Rho::Battery.refreshInterval
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
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
function show_battery_icon(){ Rho.Battery.showIcon({}); }
def show_battery_icon Rho::Battery.showIcon({}) end
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.