Android Utililty Methods Shell Run

List of utility methods to do Shell Run

Description

The list of methods to do Shell Run are organized into topic(s).

Method

intrunSuCommand(Context context, String command)
run Su Command
return runSuCommandAsync(context, command).waitFor();
ProcessrunSuCommandAsync(Context context, String command)
run Su Command Async
DataOutputStream fout = new DataOutputStream(
        context.openFileOutput(SCRIPT_NAME, 0));
fout.writeBytes(command);
fout.close();
String[] args = new String[] {
        "su",
        "-c",
        ". " + context.getFilesDir().getAbsolutePath() + "/"
...
intrunSuCommandNoScriptWrapper(Context context, String command)
run Su Command No Script Wrapper
String[] args = new String[] { "su", "-c", command };
Process proc = Runtime.getRuntime().exec(args);
return proc.waitFor();
StringgetRoot(String loc)
get Root
if (loc.startsWith("/mnt/sdcard")) {
    return "/mnt/sdcard";
} else if (loc.startsWith("/mnt/innerDisk")) {
    return "/mnt/innerDisk";
} else {
    return "/mnt/usbDisk1";
booleanrequestRootPermission(String path)
request Root Permission
Process process = null;
DataOutputStream dos = null;
try {
    process = Runtime.getRuntime().exec("su");
    if (process == null) {
        return false;
    OutputStream os = process.getOutputStream();
...
voidKillProcess()
Kill Process
android.os.Process.killProcess(android.os.Process.myPid());