首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

android java取得root权限调用linux命令

2012-09-05 
android java获得root权限调用linux命令这段代码演示了如何在Java代码里,通过调用su命令来临时修改某些文

android java获得root权限调用linux命令
这段代码演示了如何在Java代码里,通过调用su命令来临时修改某些文件的访问权限
Runtime ex = Runtime.getRuntime();
String cmdBecomeSu = "su";
String script = "busybox chmod a+rw /dev/pmem";

try{
java.lang.Process runsum = ex.exec(cmdBecomeSu);
int exitVal = 0;

final OutputStreamWriter out = new OutputStreamWriter(runsum.getOutputStream());
// Write the script to be executed
out.write(script);
// Ensure that the last character is an "enter"
out.write("\n");
out.flush();
// Terminate the "su" process
out.write("exit\n");
out.flush();

exitVal = runsum.waitFor();
if (exitVal == 0) {
Log.e("Debug", "Successfully to su");
}
} catch ( Exception e){
Log.e("Debug", "Fails to su");
}

热点排行