我在 Android 的应用程序上工作。我寻找保存来自 AT 命令的响应。例如,当我执行此命令时:
Runtime r = Runtime.getRuntime();
Process process = r.exec(new String[] {"su", "-c", "echo -e 'AT\r' > /dev/smd0"});
我想保存响应
AT
OK
我可以通过 adb 接口执行此命令来显示此响应:
# cat /dev/smd0
我在论坛上发现我应该编写此代码:
Runtime r = Runtime.getRuntime();
Process process = r.exec(new String[] {COMMAND TO EXECUTE });
BufferedReader in = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
例如,当我用“ls”替换 COMMAND TO EXECUTE 时,它工作正常。但是当我用“cat /dev/smd0”替换时,它会在 LogCat Invalide id 上显示给我:cat /dev/smd0