I want to lock screen (actually to trigger long click to show system dialog "turn off the phone?") via click button. Is it possible ? I found some examples like:
KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE);
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
But they don't work. Maybe I can switch phone off programmatically in other way? I found information that it's impossible so I'm trying to implement it like long click on lock button.
UPD: I found this:
try {
Process proc = Runtime.getRuntime()
.exec(new String[]{ "su", "-c", "reboot -p" });
proc.waitFor();
} catch (Exception ex) {
ex.printStackTrace();
}
But it also doesn't work. I'm testing it on emulator, will it work on real phone?
Thanks everyone for answers in advance !