'How can i turn on screen at android 11?

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
    setShowWhenLocked(true)
    setTurnScreenOn(true)
} else {
    window.addFlags(
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                    or WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
    )
}

with(getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        requestDismissKeyguard(this@turnScreenOnAndKeyguardOff, null)
    }
}

here is my code. This is working below android 11. But at android 11 doesnt work.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source