我想在 shell 中写入 echo -e "AT\r">/dev/smd0
然后得到它的响应。
响应将位于 \dev\smd0
中。
我搜索谷歌并发现了这个:
Runtime r = Runtime.getRuntime();
process = r.exec("su");
process = r.exec("echo -e \"AT\\r\" > /dev/smd0");
但是它不起作用。
而且我不知道如何阅读回复。
如果我安装终端模拟器,我可以编写命令并使用 cat\dev\smd0
获取其响应。
最佳答案
尝试like this :
try {
Runtime r = Runtime.getRuntime();
Process process = r.exec(" su -c 'echo -e \"AT\\r\" > /dev/smd0; cat /dev/smd0' ");
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();
}
此外,您需要手机的 root 访问权限。
关于android - 如何向android发送命令然后得到它的答案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9306813/