Turning on screen programmatically

前端 未结 5 820
情话喂你
情话喂你 2020-11-29 07:23

I would like to unlock screen and switching it on to show a popup on an event trigger. I am able to unlock the screen using

newKeyguardLock = km.newKeyguardL         


        
5条回答
  •  醉话见心
    2020-11-29 08:11

    This is very popular question but the accepted answer now is outdated.

    Below is latest way to Turn On Screen OR wake up your device screen from an activity:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
        this.setTurnScreenOn(true);
    } else {
        final Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    }
    

    Use WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON but FLAG_TURN_SCREEN_ON flag has been deprecated in API level 27 so you can use Activity.setTurnScreenOn(true) from API level 27 onward.

提交回复
热议问题