// private void acquireWakeLock(){
// if(mWakeLock==null){
// PowerManager pManager = ((PowerManager) getSystemService(Context.POWER_SERVICE));
// mWakeLock = pManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP , "MyPower");
// mWakeLock.acquire();
// }
// }
//
// private void releaseWakeLock(){
// if(null != mWakeLock && mWakeLock.isHeld()){
// mWakeLock.release();
// mWakeLock = null;
// }
// }
-------------------------------------------
public class AlarmAlertWakeLock {
private static final String TAG = "AlarmAlertWakeLock";
private static PowerManager.WakeLock sCpuWakeLock;
public static PowerManager.WakeLock createPartialWakeLock(Context context) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
return pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
}
public static void acquireCpuWakeLock(Context context) {
if (sCpuWakeLock != null) {
return;
}
sCpuWakeLock = createPartialWakeLock(context);
sCpuWakeLock.acquire();
}
public static void acquireScreenCpuWakeLock(Context context) {
if (sCpuWakeLock != null) {
return;
}
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
sCpuWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, TAG);
sCpuWakeLock.acquire();
}
public static void releaseCpuLock() {
if (sCpuWakeLock != null) {
sCpuWakeLock.release();
sCpuWakeLock = null;
}
}
}