Power: Controlling Power Resources
This tutorial demonstrates how you can access the device power state.
The Power API is mandatory for both Tizen mobile and wearable profiles, which means that it is supported in all mobile and wearable devices. All mandatory APIs are supported on the Tizen Emulators.
Warm-up
Become familiar with the Power API basics by learning about:
-
Managing the Power Resource
Request and release a specific power state.
-
Managing the Screen Brightness
Get, set, and restore the screen brightness.
-
Managing the Screen State
Switch the screen on and off, and check whether the screen is on.
Managing the Power Resource
Learning how to request and release the power state is a basic power management skill:
-
To set the power state, call the request() method of the PowerManager interface (in mobile and wearable applications) with the intended power resource and its state. In this example, the SCREEN_NORMAL state is requested for the screen resource:
tizen.power.request("SCREEN", "SCREEN_NORMAL");
-
To release a power state, call the release() method with the intended resource:
tizen.power.release("SCREEN");
-
To listen to the screen state changes, use the setScreenStateChangeListener() method:
function onScreenStateChanged(previousState, changedState) { console.log("Screen state changed from" + previousState + "to" + changedState); } tizen.power.setScreenStateChangeListener(onScreenStateChanged);
-
To unset the screen state change callback and stop monitoring it, use the unsetScreenStateChangeListener() method:
tizen.power.unsetScreenStateChangeListener();
Managing the Screen Brightness
Learning how to manage the screen brightness is a basic power management skill:
-
To get the screen brightness, call the getScreenBrightness() method of the PowerManager interface (in mobile and wearable applications):
var screenBrightness = tizen.power.getScreenBrightness();
-
To set the screen brightness, call the setScreenBrightness() method of the PowerManager interface with the value from 0 to 1.
In this example, the screen brightness is set to 1 (the brightest setting).
tizen.power.setScreenBrightness(1);
-
To restore the default screen brightness, use the restoreScreenBrightness() method of the PowerManager interface:
tizen.power.restoreScreenBrightness();
Managing the Screen State
Learning how to manage the screen state is a basic power management skill:
-
To check whether the screen is on, call the isScreenOn() method of the PowerManager interface (in mobile and wearable applications):
var isScreenOn = tizen.power.isScreenOn();
-
To switch on the screen, call the turnScreenOn() method of the PowerManager interface:
tizen.power.turnScreenOn();
-
To switch off the screen, call the turnScreenOff() method of the PowerManager interface:
tizen.power.turnScreenOff();