To Use Sudo Feature, What Should I Wrote In The My Application?
To use sudo feature, what should I write in the my application? Should I write something? If yes, can you tell me how I can write sudo application? Do I need to change manifest.xml
Solution 1:
Assuming the device is rooted and your app has been granted superuser permissions, you can use the following method to run commands as root:
publicstaticvoidrunAsRoot(String[] cmds){
Process p;
try {
p = Runtime.getRuntime().exec("su");
DataOutputStream os = newDataOutputStream(p.getOutputStream());
BufferedReader bf = newBufferedReader(newInputStreamReader(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.
Post a Comment for "To Use Sudo Feature, What Should I Wrote In The My Application?"