run Shell Root command - Android Android OS

Android examples for Android OS:Shell Command

Description

run Shell Root command

Demo Code


//package com.java2s;

import java.io.PrintWriter;

public class Main {
    public static void runCmd(String cmd) {
        try {//from  w w  w .  ja  v a2s .c om
            boolean root = true;
            if (root) {
                Process p = Runtime.getRuntime().exec("su");
                PrintWriter pw = new PrintWriter(p.getOutputStream());
                pw.println(cmd);
                pw.flush();
                pw.close();
                p.waitFor();
            } else {
                Process p = Runtime.getRuntime().exec(cmd);
                p.waitFor();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Related Tutorials