--powermanager of system services provided by Android (Power service)
--Reprint Please specify source: Coder-pig
Introduction to this section:
This section focuses on Android for the system services we provide: An API for PowerManager power management,
Used to manage CPU running, keyboard or screen lit up; but unless it's a necessity, otherwise, you should try to avoid
Use this class, and be sure to release it when you're done with it! This section is not too deep to explain, because this design to the bottom of the
Some things, in the future need to use further research, and then write another blog summary! So this section describes the main
Some basic concepts, powermanager,wakelock lock mechanism and so on!
The knowledge point diagram of this section:
code Example:
A tool class for managing Wakelock and power management for Android devices:
Import Android.content.context;import Android.content.sharedpreferences;import Android.os.powermanager;import Android.preference.preferencemanager;public class Managewakelock {private static Powermanager.wakelock MWakeLock = nul L private static Powermanager.wakelock Mpartialwakelock = null; Private static Final Boolean Prefs_screenon_default = true; Private static Final Boolean prefs_dimscreen_default = false; private static final String Prefs_timeout_default = "30"; public static synchronized void Acquirefull (Context mcontext) {if (Mwakelock! = null) {return; } PowerManager mPm = (powermanager) mcontext.getsystemservice (Context.power_service); Sharedpreferences mprefs = preferencemanager.getdefaultsharedpreferences (Mcontext); int flags; Flags = Powermanager.screen_bright_wake_lock | Powermanager.acquire_causes_wakeup; Mwakelock = Mpm.newwakelock (Flags, "Managerwakelock"); Mwakelock.setreferencecoUnted (FALSE); Mwakelock.acquire (); } public static synchronized void acquirepartical (Context mcontext) {//check If partial lock already exists if (mpartialwakelock! = null) {return; } PowerManager mPm = (powermanager) mcontext.getsystemservice (Context.power_service); Mpartialwakelock = Mpm.newwakelock (Powermanager.screen_bright_wake_lock | Powermanager.acquire_causes_wakeup, "Managerwakelock"); Mpartialwakelock.setreferencecounted (FALSE); Mpartialwakelock.acquire (); }} public static synchronized void Releasefull () {if (Mwakelock! = null) {mwakelock.release (); Mwakelock = null; }} public static synchronized void Releasepartial () {if (Mpartialwakelock! = null) {Mpartialwa Kelock.release (); Mpartialwakelock = null; }} public static synchronized void Releaseall () {ReleasEfull (); Releasepartial (); }}
Resources:
Http://www.open-open.com/lib/view/open1343207436974.html
http://blog.csdn.net/xieqibao/article/details/6562256
Http://blog.chinaunix.net/uid-27411029-id-4040727.html
--powermanager of system services provided by Android (Power service)