博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java root权限_android java获得root权限调用linux命令 | 学步园
阅读量:1532 次
发布时间:2019-04-21

本文共 866 字,大约阅读时间需要 2 分钟。

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");

}

这段代码演示了如何在Java代码里,通过调用su命令来临时修改某些文件的访问权限

如果是测试程序,必须要root或者system权限可以用

android.permission.FACTORY_TEST 作为一个工厂测试程序,运行在root用户(Run as a manufacturer testapplication, running as the root user. )

摘自:

http://wyoojune.blog.163.com/blog/static/5709332520111011104026490/

转载地址:http://bekdy.baihongyu.com/

你可能感兴趣的文章
批量读取图片中关于缺失dirent.h的问题
查看>>
心态与幸福
查看>>
编程是一个及其痛苦的事
查看>>
warning C4018: “<”: 有符号/无符号不匹配
查看>>
一次表扬
查看>>
思想的启蒙与宽容
查看>>
malloc函数未定义
查看>>
最美好的岁月
查看>>
vector的应用举例
查看>>
哪瓶水有毒
查看>>
爱与失落
查看>>
谁辜负了谁
查看>>
不可思议的闪电奇缘
查看>>
什么是爱
查看>>
排序算法(一)——简单选择排序
查看>>
时间与梦想
查看>>
我的心太乱
查看>>
家教与感恩
查看>>
数据结构考研复习要点2016
查看>>
思想汇报(一)——努力的意义
查看>>