I have set up my app to execute the su
command using this code:
try {
Runtime.getRuntime().exec("su");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
altDialog.setTitle("No Root");
altDialog
.setMessage("I am afraid I have been unable to execute the su binary. Please check your root status.");
altDialog.setCancelable(false);
altDialog.setButton("Exit App",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
Log.e("Android .img Flasher",
"Exiting due to root error");
finish();
}
});
}
This catches if the su
command doesn't exist (I believe), but not if root was actually granted.
How would I be able to check if root was actually granted?
On a side note, how would I be able to store the output of a command using the Runtime.getRuntime.exec()
command?
You can use the code bellow. I've wrote it for generic command use, but it works with
su
command as well. It returns if the command succeed as well as the command output (or error).You call it with two arguments:
command
- string with command to executeresults
- empty ArrayList to return the command output. If null, output is not returned.To check
su
command you can do the following:Regards.