Assuming the device is rooted and your app has been granted superuser permissions, you can use the following method to run commands as root:
public static void runAsRoot(String[] cmds){
Process p;
try {
p = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(p.getOutputStream());
BufferedReader bf = new BufferedReader(new InputStreamReader(p.getInputStream()));
for (String tmpCmd : cmds) {
os.writeBytes(tmpCmd+"\n");
String test;
while((test = bf.readLine()) != null)
{
Log.i(TAG, test);
}
}
//os.writeBytes("exit\n");
os.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
Just pass it a list of commands in a String array.
4
solved To use sudo feature, what should I wrote in the my application?