用于Android设备执行Linux命令语句,更改root权限等
import java.io.*;
public static boolean RootCommand(String command){
Process process = null;
DataOutputStream os = null;
try{
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes(command + "\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
}catch(Exception e){
Log.d("*** DEBUG ***", "ROOT REE" + e.getMessage());
return false;
}finally{
try{
if(os != null){
os.close();
}
process.destroy();
}catch(Exception e){
}
}
Log.d("*** DEBUG ***", "ROOT SUC");
return true;
}调用示例:
//String apkRoot = "chmod 777" + getPackageCodePath();//获取整个apk权限 String apkChmod = "chmod 777 "+"/dev/video0";
RootCommand(apkChmod);
本文介绍了一种在Android设备上通过Java代码执行Linux命令的方法,包括更改文件或目录的权限等操作。文中提供了一个名为RootCommand的具体实现示例。
1064

被折叠的 条评论
为什么被折叠?



