i want to switch off my mobile through coding please can any one help me .what is the permission required for that application and what is the coding required. Thanks in advance
Asked
Active
Viewed 1,574 times
2 Answers
0
The only possibility i know to shut down device is with root command :
try {
String[] str ={"su","-c","reboot -p"};
Process p = Runtime.getRuntime().exec(str);
if(p.waitFor()==127 || p.waitFor()==255){
//no root, error
}
} catch (Exception e) {
}
Another possibility is to look android sources to look who the system make shutdown but to make it work your application need to be in /system/app folder (so you have to be root to do this). And if you have root my solution is simple for final user.

jaumard
- 8,202
- 3
- 40
- 63
0
You could possibly use the PowerManager to make it reboot (this does not guarantee that it'll reboot - OS may cancel it):
http://developer.android.com/reference/android/os/PowerManager.html#reboot(java.lang.String)
It requires the REBOOT permission:
http://developer.android.com/reference/android/Manifest.permission.html#REBOOT
Can you also check your logcat when trying to enable/disable keyguard, and post what's there?

Akash
- 206
- 1
- 4