Saturday, 15 March 2014

Android - How to know when Super User is granted to my Application? -


My app needs root access, for example this code:

  process p ; Try {p = Runtime.at timetime}. Exec ("su"); BufferDriver SS = New buffed reader (new input striker reader (P. JARRstream ()); String line; If (line = es.readLine ()) = null () (if line content acquails ("permission denied")) log.e ("trisTag", "root is not provided"); }} Hold (IOException e) {// TODO auto-generated cal block e.printStackTrace (); }   

So I know that when my root access is denied (read from the error stream). But what about it? How to go

Answers

  public class root {private static string LOG_TAG = Root.class.getName (); The public is Boolean, the device root () (if (checkup method 1 ()) {returns true;} if (checker2 method) () is true;} if (checker method 3 ()) {return true;} return return; } Public Boolean Check RootMethod1 () {String build tag = android.os.build.TAGS; if (build tag! = Null & build tagcountains ("test-keys")} {return true;} description is false;} public boolean check Try RootMethod2 () {file file = new file ("/ system / app / superuser. Apk"); if (file.exists ()) {back true ;}} Hold (exception e) {} return false;} public boolean checkovermouth 3 () (if new ExecShell) execution command (SHELL_CMD.check_su_binary)! = Null) {back true; } Other {return false; }}}   

/ ** * @ Author Kevin Kovalsky * * / Public Class ExecShell {Private Static String LOG_TAG = ExecShell.class.getName (); Public static Enum SHELL_CMD {check_sub_bani (new string [] {"/ system / xbin / joe", "su"}) ;; String [] command; SHELL_CMD (string [] command) {this.command = command; }} Public Arrestist & lt; String & gt; ExecuteCommand (SHELL_CMD shellCmd) {string line = zero; ArrayList & LT; String & gt; FullRespens = New Arrestist & lt; String & gt; (); Local process process = null; {LocalProcess = Runtime.getRuntime (). Try Exec (shellCmd.command); } Hold (exception e) {return tap; } BufferedWriter = New Buffed Out Vires (New OutputStream Water (localProcess.getOutputStream ()); BufferedReader = new in BufferedReader (New InputStreamReader (localProcess.getInputStream ())); Try {while ((line = in.readLine ()) = null) {log d. (LOG_TAG, "- & gt; line received:" + line); FullResponse.add (line); }} Hold (exception e) {e.printStackTrace (); } Log D. (LOG_TAG, "-> The full answer was:" + FullSpons); Complete return; }

No comments:

Post a Comment