Light up screen when notification received android

后端 未结 2 729
小鲜肉
小鲜肉 2020-12-02 15:38

I have a service running for my application to send notification every hour. This is working fine as i heard a sound and a vibration every hour because of my notification bu

2条回答
  •  渐次进展
    2020-12-02 16:38

    There is my solution:

    createNotification(); //your implementation
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    boolean isScreenOn = Build.VERSION.SDK_INT >= 20 ? pm.isInteractive() : pm.isScreenOn(); // check if screen is on
    if (!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

提交回复
热议问题