java - 如何以编程方式从 android studio 运行 cmd/shell 命令?
问题描述
我已经运行了以下代码行和一些类似的解决方案,但似乎没有任何效果:
StringBuilder cmdOut = new StringBuilder();
Process process;
try {
process = Runtime.getRuntime().exec("adb shell");
InputStreamReader r = new
InputStreamReader(process.getInputStream());
BufferedReader bfreader = new BufferedReader(r);
char [] buf = new char[4096];
int nRead = 0;
while((nRead = bfreader.read(buf)) > 0)
{
cmdOut.append(buf,0,nRead);
}
bfreader.close();
try{
process.waitFor();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
catch (IOException e)
{
e.printStackTrace();
}
but when i run this i got the following error:I have looked after every answer but I have not found any working solution
java.io.IOException: Cannot run program "adb": error=13, Permission denied
如果有人有任何可行的解决方案,请与示例分享。
解决方案
您不能直接从 android 设备执行 ADB。
您需要编写一个桌面应用程序来执行命令并且可以由 android 应用程序调用,或者(更容易)使用自动化软件从您的手机调用远程命令。
推荐阅读
- pdf-generation - High resolution scatterplot in GNUPlot?
- android - ionic 3在后台应用程序上保持套接字连接打开
- verilog - 该代码的等效硬件电路是什么?
- javascript - Get shuffled, non-repeated items across multiple pages
- matlab - 在 MATLAB 中使用数组中的值填充矩阵
- javascript - 我可以通过键入代码而不是单击元素来访问 URL 吗?
- elixir - 从 GenServer 检索所有状态
- angular - 版本角捕捉
- c# - 如何更改 C# Web 表单中的 GridView 列标题文本?
- javascript - 使用 JavaScript 对象为 Google 图表创建新对象