Android 电源锁

2019-07-13 21:41发布

WakeLock wakeLock = null; private void acquireWakeLock() { if (null == wakeLock) { PowerManager pm = (PowerManager)this.getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK|PowerManager.ON_AFTER_RELEASE, "PostLocationService"); if (null != wakeLock) { wakeLock.acquire(); } } } private void releaseWakeLock() { if (null != wakeLock) { wakeLock.release(); wakeLock = null; } }