如何从Android应用程序运行root的命令? [英] How to run root commands from Android application?

查看:366
本文介绍了如何从Android应用程序运行root的命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要写在其上安装了该设备,我的意思是通过安装此应用程序,它的根,你将能够以root您的设备没有一台电脑,一个应用程序就像在以下链接的应用程序,

I want to write an application which roots the device on which it is installed, I mean by installing this app you will be able to root your device without a computer, just like the app in the following link,

http://www.kingoapp.com/root-tutorials/how-to-root-android-without-computer.htm

我搜索上如何做到这一点使用Java code为Android设备,但没有明确的解决方案,我很多。根据我的研究,我认为我们需要进行如下操作:

I've searched a lot on how to do that using Java code for Android devices, but there was no clear solution to me. Based on my research, I think we need the following steps:

1 - 如果能够使用调用Runtime.getRuntime()使用shell命令Android中的exec();

1- Being able to use shell commands in Android using Runtime.getRuntime().exec();

2 - 执行该获得root权限的命令(我认为,但这需要一个根深蒂固的设备被执行)。

2- Executing a command that gains root privileges (I think su, but this needs a rooted device to be executed).

3启动一个root的命令,将根设备。

3- Initiate a root command that will root the device.

我找不到如何做到上面的步骤一个code解释。我想先了解这一过程,可以在它使用的命令,那么我想尝试自己来实现它。由于有上提供此功能店里许多应用程序,然后实现它必须是可行的。

I couldn't find a code explanation on how to do the steps above. I want to understand this process first, the commands that can be used in it, then I want to try to implement it by myself. Since there are many apps on the store that offer this feature, then implementing it must be feasible.

任何人都可以请向我解释如何实现这个过程吗?

Could anyone please explain to me how to implement this process?

此外,有没有写一个code为相反的过程,这是unrooting该设备的可能性?

Also, is there a possibility to write a code for the opposite process, which is unrooting the device?

任何帮助是AP preciated。

Any help is appreciated.

感谢。

推荐答案

要运行root的命令,你必须使用以下格式:

To run root commands, you have to use the following format:

    public void RunAsRoot(String[] cmds){
            Process p = Runtime.getRuntime().exec("su");
            DataOutputStream os = new DataOutputStream(p.getOutputStream());            
            for (String tmpCmd : cmds) {
                    os.writeBytes(tmpCmd+"\n");
            }           
            os.writeBytes("exit\n");  
            os.flush();
}

在那里你在一个字符串数组传递,每个字符串是一个需要执行的命令。例如:

where you pass in an array of strings, each string being a command that needs to be executed. For example:

的String [] = CMDS {sysrw,RM /data/local/bootanimation.zip,sysro};

这篇关于如何从Android应用程序运行root的命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆