android保持在休眠时,后台程序继续运行(让程序获取设备电源锁)

//在获取电源锁的程序中,必须在其Manifest.xml文件中加入下面的权限:

<uses-permission android:name="android.permission.WAKE_LOCK" />


private PowerManager.WakeLock mWakeLock; //申请设备电源锁 private void acquireWakeLock() { if (null == mWakeLock) { PowerManager pm = (PowerManager)this.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK|PowerManager.ON_AFTER_RELEASE,""); if (null != mWakeLock) { mWakeLock.acquire(); } } } //释放设备电源锁 private void releaseWakeLock() { if (null != mWakeLock) { mWakeLock.release(); mWakeLock = null; } }

 

【原创笔记】手机休眠后,定时唤醒你的后台服务

http://my.eoe.cn/indexer/archive/4587.html

Android系统休眠和定时唤醒讨论

http://bbs.csdn.net/topics/340139059

你可能感兴趣的:(android)