如何执行壳牌通过Android应用程序的命令?应用程序、壳牌、命令、Android

2023-09-07 01:48:27 作者:回忆曾经寂如流年°

首先,我是新来的Andr​​oid。

Firstly I'm new to Android.

如何执行下面的shell命令

How to execute the following shell command

echo "1" > /sys/devices/enable

在一个Android应用程序。

in an android app.

我提到很多环节的,但我没有得到解决。

I referred many link's but I didn't get the solution.

有没有办法,我要提到的manifest文件来执行shell命令在应用程序的任何许可???

Is there any permission that I should mention in the manifest file to execute the shell commands in the app???.

在此先感谢。

推荐答案

为什么在Java中不写?

Why not write in Java?

try{
    FileWriter fw = new FileWriter(new File("/sys/devices/enable"));
    fw.write('1');
    fw.close();
}catch(IOExceprion e){}

如果你真的想调用一个shell,试试这个:

If you really want to invoke a shell, try this:

Runtime rt = Runtime.getRuntime();
Process p = rt.exec(new String[]{"/system/bin/sh", "-c", "echo \"1\" > /sys/devices/enable");

尝试上述任何一种方法之前,可以先

请确保您的设备是植根第一。

Make sure your device is rooted first before trying any of the above mentioned approaches.