【发布时间】:2013-07-12 12:54:58
【问题描述】:
我试图以编程方式截取 Android 屏幕的屏幕截图。我已经完成了以下代码:
private void getsnap(){
try{
Process sh = Runtime.getRuntime().exec("su", null, null);
OutputStream os = sh.getOutputStream();
String filePath = this.getFilesDir().getPath().toString() + "/fileName1.jpeg";
os.write(("/system/bin/screencap -p " + filePath).getBytes("ASCII"));
os.flush();
os.close();
sh.waitFor();
}
catch (Exception e)
{
e.printStackTrace();
}
}
java.io.IOException: write failed: EPIPE (Broken pipe)
请问有人可以帮忙吗?我已经检查了其他帖子,但没有找到任何解决我问题的方法。
编辑:
请注意,错误发生在os.write() 行中。
【问题讨论】:
-
你的设备有root权限吗?
-
@Alex- 我只是在模拟器上运行它。在其中一篇文章中,我发现,我不必拥有 root 权限。可能是错的。请你帮我如何在模拟器上获得root权限?
-
您正在尝试使用来自 /system/bin 的系统命令。我假设您需要 root 权限才能在模拟器上调用它。不过你可以试试这个截图方法:stackoverflow.com/questions/2661536/…
标签: android file outputstream android-permissions epipe