您的位置:首页 > 运维架构 > Linux

Android设备执行Linux命令语句

2017-10-18 10:17 148 查看
用于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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: