【发布时间】:2018-05-29 20:16:42
【问题描述】:
我在 Java 程序中有以下方法
public static void enableAirplaneMode() {
String s = null;
try {
Runtime rt = Runtime.getRuntime();
Process pr = null;
String command = "adb shell \"su -c 'settings put global airplane_mode_on 1'\"";
System.out.println(command);
pr = rt.exec(command);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(pr.getInputStream()));
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
pr.destroy();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
上述方法的输出是
adb shell "su -c 'settings put global airplane_mode_on 1'"
/system/bin/sh: no closing quote
但是,如果我直接在终端中复制/粘贴命令,一切都会按预期工作。为什么我在这里收到“没有结束引号”错误?
【问题讨论】:
-
试试passing an array
String[] command = {"adb", "shell", "su -c 'settings put global airplane_mode_on 1'"};。 -
行得通,您可以将其发布为答案,我会接受它
-
欺骗 stackoverflow.com/questions/31776546/… 和 stackoverflow.com/questions/48425729/… 可能还有更多我无法快速找到