You can control the device screen saver with the Nokia UI API. By default, the screen saver starts automatically if the device user does not press any key within a certain timeframe (set to 5 seconds by default on Symbian devices). You can prevent this by keeping the screen backlight active with the Nokia UI API. The Nokia UI API provides two methods for controlling the screen backlight:
If your target device supports Nokia UI API 1.4 or newer, use the DeviceControl.resetUserInactivityTime
method, since it does
not change the screen brightness.
Note: Forcing the display to be constantly switched on consumes more battery. To take this into account, program the MIDlet to disable the screen saver only when on the foreground, for example.
The DeviceControl.setLights
method activates
and deactivates the screen backlight on the device. When used to activate
the backlight, the method switches the backlight on and resets the
user inactivity timers on the device. If called in a loop, the backlight
activation prevents the screen saver from starting.
Using the DeviceControl.setLights
method to prevent the screen saver
from starting is supported since Series 40 1st Edition and S60 3rd
Edition, Feature Pack 1.
Note: Using the DeviceControl.setLights
method overrides the device's ambient light sensor settings and
can thus change the screen brightness.
Note: Resetting the user inactivity timers also prevents the automatic keypad lock from being activated.
The following example shows how
to use the DeviceControl.setLights
method to prevent
the screen saver from starting. The screen saver timeout value is
configurable, but it cannot be accessed using Java, so a hard-coded
value is used in the example loop.
class DisableScreenSaver extends Thread { public void run() { while(true) { DeviceControl.setLights(0, 100); try { Thread.sleep(4000); // minimum screen saver timeout in UI is 5 seconds } catch (InterruptedException e) { } } } } public class MyMidlet extends MIDlet { public void startApp() { new DisableScreenSaver().start(); ... } ... }
The DeviceControl.resetUserInactivityTime
method
resets all the user inactivity timers on the device. If called in
a loop, resetting the user inactivity timers prevents the screen saver
from starting.
The DeviceControl.resetUserInactivityTime
method is supported since Nokia UI API 1.4 on Java Runtime 2.1 for
Symbian and newer.
To determine whether the device supports
the DeviceControl.resetUserInactivityTime
method,
use the com.nokia.mid.ui.screensaverprevention
system property.
Note: Using the DeviceControl.resetUserInactivityTime
method does not change the screen brightness.
Note: Resetting the user inactivity timers also prevents the automatic keypad lock from being activated.
The following example
shows how to use the DeviceControl.resetUserInactivityTime
method to prevent the screen saver from starting. The screen saver
timeout value is configurable, but it cannot be accessed using Java,
so a hard-coded value is used in the example loop.
class DisableScreenSaver extends Thread { public void run() { while(true) { DeviceControl.resetUserInactivityTime(); // reseting all user inactivity timers try { Thread.sleep(4000); // minimum screen saver timeout in UI is 5 seconds } catch (InterruptedException e) { } } } } public class MyMidlet extends MIDlet { public void startApp() { new DisableScreenSaver().start(); ... } ... }