愤怒的西北狼 2014-11-05 05:55 采纳率: 0%
浏览 2125

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条回答

  • 关注

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

                } catch (Exception e) {
                    e.printStackTrace();
                }
                        //我写的一个重启的命令有效的
    
    评论

报告相同问题?

悬赏问题

  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 CSS实现渐隐虚线框
  • ¥15 有没有帮写代码做实验仿真的
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?