java root权限_android java获得root权限调用linux命令 | 学步园
发布日期:2021-06-24 11:23:48 浏览次数:3 分类:技术文章

本文共 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/

转载地址:https://blog.csdn.net/weixin_32473663/article/details/114054633 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:java最小化窗体_JAVA窗体最大化最小化控制+托盘
下一篇:弹性方法计算连续梁板内力_(梁板结构)混凝土结构设计复习题及答案

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2024年04月02日 10时21分45秒