Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
New Developer
pnewhook
Posts: 70
Registered: ‎01-13-2011
My Device: Torch 9800 and Playbook
My Carrier: Rogers

When the Battery Low Dialog Shows, Does My Playbook Webworks app Receive the toBackground Action

I'm assuming there's a modal dialog that shows up when the battery is low. Is my app somehow automatically paused when this happens? Or can I respond to a toBackground event? I'd need to pause a game loop.

Please use plain text.
Administrator
astanley
Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: When the Battery Low Dialog Shows, Does My Playbook Webworks app Receive the toBackground Action

When the battery level is low, the Tablet OS initates a system event.  There is no modal dialog window, however there is a battery icon in the system tray.

 

From your WebWorks application, you can listen to the battery level system event, and respond accordingly (such as pausing or suspending your application if you determine the battery is at a critically low level).

 

Here's a sample that demonstrates how to use the battery system event from within a WebWorks application:\

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" id="viewport" content="height=device-height,width=device-width,user-scalable=no" />
<title>System</title>
<script type="text/javascript">
   function handleBatteryLevel(level)
   {
      var ele = document.getElementById("batteryLevel");
      if (ele)
      {
         ele.innerHTML = "Battery Level: " + level;
      }
      document.getElementById("level").style.width = level + "%";
   }
	
   function setHandlers()
   {
      blackberry.system.event.deviceBatteryLevelChange(handleBatteryLevel);
   }
</script>
<style type="text/css">
	.batteryLevelBar
	{
		border: solid 1px black;
		background-color: white;
		clear: both;
	}
	.batteryLevel
	{
		background-color: lime;
		display: block;
	}
</style>
</head>

<body onload="setTimeout(setHandlers, 1000)">
<h1>System Event API</h1>

<h2>Events</h2>
<div class="demo">
	<div id="batteryLevel"></div>
	<div class="batteryLevelBar">
		<div id="level" class="batteryLevel">&nbsp;</div>
	</div>
</div>
</body>
</html>

 

 

Cheers,

Adam

 

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
Please use plain text.