Wake up Android Phone/tablet?

后端 未结 1 1388
暖寄归人
暖寄归人 2020-12-18 07:12

I\'ve got a push notification-app, is there any way to wake up the screen (just make it light up) whenever I receive a push notification?

if you want some code just

相关标签:
1条回答
  • 2020-12-18 07:53

    You can do it using a WakeLock this way:

    When you set your notification:

    WakeLock screenOn = ((PowerManager)getSystemService(POWER_SERVICE)).newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "example");
    screenOn.acquire();
    

    And, IMPORTANT, release the wakelock when you don't need it anymore:

    screenOn.release();
    
    0 讨论(0)
提交回复
热议问题