How to send Android device to sleep or programmatically press the power button(KEYCODE_POWER) with Kotlin? Is it possible? Some example?
Thank you advance!
How to send Android device to sleep or programmatically press the power button(KEYCODE_POWER) with Kotlin? Is it possible? Some example?
Thank you advance!
In Android (regardless of whether you use Kotlin, Java, whatever) for security reasons it is not possible for an app to make the device sleep, unless your app is a system app provided by the phone manufacturer.
Maybe you still can. Rather old post here https://forum.xda-developers.com/showthread.php?t=1210421 says to use gotosleep function. There are discussions of problems with it for Java - see below links, but maybe for Kotlin it will work.
Android system application DEVICE_POWER permission error
Android What permissions required to call PowerManager.goToSleep(n) put device in sleep mode?