root - How to Shutdown Android 4.0 rooted Device programatically -


please me find out solution this, know there many questions , duplicates same here describe whole things tried.

i have 1 android device installed 4.0 version of android. want shutdown device using 1 demo application.

1) demo application signed platform keys used in built in file system. 2) device rooted development board , have permissions on this. 

application contains following things

1) application system application 2) application signed platform keys used in built in file system. 

for make automation easier, did import key/cert pair java keystore file, keytool-importkeypair , use eclipse signing.

used command mentioned below.

commad : keytool-importkeypair -k ~/desktop/myown.keystore -p android -pk8 platform.pk8 -cert platform.x509.pem -alias platform

i used following code reboot never make success in .i read many questions , answers on stackoverflow said require

1) root access of device 2) signed apk 1 keys available on `build/target/product/security/` 3) given proper permission in androidmanifest.xml file. 

am right in alomg points?

application code :

first try

public static void shutdown2() {  runtime runtime = runtime.getruntime(); process proc = null; outputstreamwriter osw = null;  string command = "/system/bin/reboot -p";  try { // run script      proc = runtime.exec("/system/xbin/su");     osw = new outputstreamwriter(proc.getoutputstream());     osw.write(command);     osw.flush();     osw.close();  } catch (ioexception ex) {     ex.printstacktrace(); } {     if (osw != null) {         try {             osw.close();         } catch (ioexception e) {             e.printstacktrace();         }     } } try {     if (proc != null)         proc.waitfor(); } catch (interruptedexception e) {     e.printstacktrace(); } if (proc.exitvalue() != 0) { }  } 

second try :

private void shutdown3() {         try {              string[] cmd = { "/system/bin/sh","su","reboot -p"};              process proc = runtime.getruntime().exec(cmd);             proc.waitfor();         } catch (exception ex) {             log.i("tag", "could not reboot 3  ", ex);         }     } 

3rd try :

private void shutdown() {         try {             process proc = runtime.getruntime().exec(                     new string[] { "/system/bin/su", "-c",                             "/system/bin/reboot -p" });             proc.waitfor();         } catch (exception ex) {             log.i("tag", "could not reboot 1 ", ex);         }     } 

in 3rd method tried "/system/bin/su"

the below code worked me

        process process = runtime.getruntime()                 .exec(new string[]{ "su", "-c", "busybox poweroff -f"});         process.waitfor(); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -