Light up screen when notification received android Light up screen when notification received android android android

Light up screen when notification received android


PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);boolean isScreenOn = pm.isScreenOn();Log.e("screen on.................................", ""+isScreenOn);if(isScreenOn==false){    WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK |PowerManager.ACQUIRE_CAUSES_WAKEUP |PowerManager.ON_AFTER_RELEASE,"MyLock");    wl.acquire(10000);    WakeLock wl_cpu = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"MyCpuLock");    wl_cpu.acquire(10000);}


There is my solution:

createNotification(); //your implementationPowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);boolean isScreenOn = Build.VERSION.SDK_INT >= 20 ? pm.isInteractive() : pm.isScreenOn(); // check if screen is onif (!isScreenOn) {    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "myApp:notificationLock");    wl.acquire(3000); //set your time in milliseconds}

More at PowerManager