//手機已經root了,這些命令用MT管理器可以執行
//不曉得為啥用我的app就執行不了了
public static String exec(String command) {
Process process = null;
BufferedReader reader = null;
InputStreamReader is = null;
DataOutputStream os = null;
try {
process = Runtime.getRuntime().exec("su");
is = new InputStreamReader(process.getInputStream());
reader = new BufferedReader(is);
os = new DataOutputStream(process.getOutputStream());
os.writeBytes( "mount -o rw,remount /system\n");
os.flush();
os.writeBytes( "cp /sdcard/測驗 /system/app/yry.apk\n");
os.flush();
os.writeBytes( "chmod 644 /system/app/yry.apk\n");
os.flush();
os.writeBytes("exit\n");
os.flush();
int read;
char[] buffer = new char[4096];
StringBuilder output = new StringBuilder();
while ((read = reader.read(buffer)) > 0) {
output.append(buffer, 0, read);
}
process.waitFor();
return output.toString();
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
} finally {
try {
if (os != null) {
os.close();
}
if (reader != null) {
reader.close();
}
if (is != null) {
is.close();
}
if (process != null) {
process.destroy();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/36088.html
標籤:Java相關
