Reputation: 1208
I am finding out a way to switch off my tablet automatically.
Right now when we long press power button, I get a confirmation for shutdown (Cancel or Ok). Is there a way to programmatically switch off the device without confirmation ?
Is this possible?
Upvotes: 2
Views: 3233
Reputation: 8979
Although you can't really invoke the shutdown programmatically in non-rooted device, there's a way how to disable the confirmation dialog that occurs when you long-press the power button. There's a secret code
*#*#7594#*#*
or
*#7594#
which changes the power button behaviour - enables direct power off once the code enabled. You need to choose this code via default dialpad. Works on most Android phones.
Here's the list of some other secret codes.
Upvotes: 0
Reputation: 6721
This is a dicey one! As an app, you cant do much, but there is one way you can try this. Get a phone which is rooted and grants your application SuperUser permissions. Then you could try to run this piece of code from your APK.
Process mProcess = null;
DataOutputStream osStream;
try {
mProcess = Runtime.getRuntime().exec("su");
} catch (IOException e) {
Log.e("Error","Unable to get SU permissions, quitting");
}
osStream = new DataOutputStream(mProcess.getOutputStream());
try {
osStream.writeBytes("reboot");
Thread.sleep(1000);
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
Not a tested piece of code, but hopefully should give you some idea!
Upvotes: 2
Reputation: 15414
No. Suitably rooted phones/tablets often have access to su/reboot commands, but for an off-the-shelf, commercially available device, no: there is no way to programatically shut it down.
Upvotes: 3