Tuesday, January 27, 2009

Code: Enable the backlight and prevent the screen from turning off


Some BlackBerry device screens, such as those on the BlackBerry 7100 series, become blank when not in use. BlackBerry device users can configure the screen timeout period.

You might prefer to control when the screen is turned on or off. For example, when implementing a peripheral keyboard you can simulate key events to make sure that the screen does not turn off while the BlackBerry device user types or navigates on the BlackBerry device.

The following code specifies that the screen backlight, once activated, has a timeout period of 30 seconds.

Code:

if(( Display.getProperties()
  & Display.DISPLAY_PROPERTY_REQUIRES_BACKLIGHT) != 0 )
{
    Backlight.enable( true, 30 );
}

The backlight.enable method only turns the backlight on for the period of time specified, up to a maximum of 255 seconds. BlackBerry device user activity that occurs while the backlight is on resets the value specified in this method.

However, some applications might require the backlight to stay on for longer than 255 seconds. For example, in navigation software design, the backlight might be required for extended periods of time even though BlackBerry device user activity is not continuous (e.g., while travelling). For this scenario, you can set a timer to turn the backlight on every 255 seconds.

Remember that BlackBerry device backlight usage consumes additional power. Excessive usage has a negative impact on the BlackBerry device battery.

Note: The code sample above requires code signing. See the Controlled APIs and Code Signing page for more information.

No comments:

Post a Comment

Place your comments here...