Dev/Android

[Android] 꺼진 화면 켜기

healthyryu 2022. 3. 24. 17:31

Android 앱에서 디스플레이가 꺼져있을 경우에 디스플레이를 켜는 방법

private fun screenTurnOn() {
    val powerManager: PowerManager =
        getSystemService(Context.POWER_SERVICE) as? PowerManager? ?: return

	val isScreenOn = powerManager.isInteractive
    if (!isScreenOn) {
        powerManager.newWakeLock(
            PowerManager.PARTIAL_WAKE_LOCK or PowerManager.ACQUIRE_CAUSES_WAKEUP,
            MessageService::class.simpleName
        ).run {
            acquire(1)
        }
    }
}
반응형