Android: How to turn screen on and off programmatically?

后端 未结 16 2289
醉酒成梦
醉酒成梦 2020-11-22 13:05

Before marking this post as a \"duplicate\", I am writing this post because no other post holds the solution to the problem.

I am trying to turn off the device, then

16条回答
  •  轮回少年
    2020-11-22 13:34

    I had written this method to turn on the screen after screen lock. It works perfectly for me. Try it-

        private void unlockScreen() {
            Window window = this.getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
            window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
            window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
        }
    

    And call this method from onResume().

提交回复
热议问题