0

我尝试了以下方式,但它不适合我:

public void RunAsRoot(String cmnd){
        Process p = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(p.getOutputStream());                        
        os.writeBytes(cmnd +"\n");                     
        os.writeBytes("exit\n");  
        os.flush();
        p.waitFor();
}

我也试过这个:

public void RunAsRoot(String cmds){
        Process p = Runtime.getRuntime().exec("su -c " + cmds);
        p.waitFor();
}

但是上述方法都不起作用。但是,以下命令通过 adb 在 shell 中为我工作:

 su -c "input" " keyevent" " 3"

所以我什至试过这个:

public void RunAsRoot(String cmds){
        Process p = Runtime.getRuntime().exec("su -c \"input\" \" keyevent\" \" 3\"");
        p.waitFor();
}

但即使这样也没有用。谁能帮帮我吗!!!!

4

1 回答 1

0

我用 aOutputStream而不是 aDataOutputStream

sh = Runtime.getRuntime().exec("su", null,null);
String now =  c.get(Calendar.YEAR) + "-" + c.get(Calendar.MONTH) + "-" + c.get(Calendar.DAY_OF_MONTH) + "-" + c.get(Calendar.HOUR)+":"+c.get(Calendar.MINUTE);
Log.d(TAG, "Creating screenshot " + now +".png");
OutputStream  os = sh.getOutputStream();
os.write(("/system/bin/screencap -p " + "/data/local/" + now +".png").getBytes("ASCII"));
os.flush();
os.close();
sh.waitFor();
于 2014-12-17T11:01:04.643 回答