2 djwmzyl djwmzyl 于 2014.11.05 13:55 提问

Android中调用shell命令;

public static int execCommand(String command) throws IOException {
return execCommand(new String[] { "sh","-c", command });

}
/**
* Execute shell command
* @param command Shell command array
* @return Result
* @throws IOException Throws when occurs #IOException
*/
public static int execCommand(String[] command) throws IOException {
Log.d("Darrick", "command = "+command);
int result = RESULT_FAIL;
Runtime runtime = Runtime.getRuntime();

Process proc = runtime.exec(command);

}
其中String command = "echo > 0 /sys/bus/platform/drivers/battery/Charging_switch";本来打算是应用检测到电量为100%时自动执行该命令,不让机器充电;但是实现不了,求高手解答;谢谢;

1个回答

q3733353520
q3733353520   2015.06.18 18:13

String tTempString = new String("su -c reboot");
//StandByMode = false;
int r = 0;
try {
Process process = Runtime.getRuntime().exec(tTempString);

            } catch (Exception e) {
                e.printStackTrace();
            }
                    //我写的一个重启的命令有效的
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!