codice:
TextView tv = (TextView) findViewById(R.id.test);
Process p;
try {
p = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes("echo \"CIAO MAMMA!!!!!!!!\" >/system/sd/ciccio.txt\n");
os.writeBytes("exit\n");
os.flush();
try {
p.waitFor();
if (p.exitValue() != 255) {
tv.setText("OK!");
}
else {
tv.setText("Errore nella richiesta permessi di Root");
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Ovviamente c'è da implementare le eccezioni e la logica di business