我试图以编程方式截取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();
}
}
Run Code Online (Sandbox Code Playgroud)
java.io.IOException: write failed: EPIPE (Broken pipe)
请有人帮忙吗?我已经检查过其他帖子,但我找不到解决问题的方法.
编辑:
请注意,错误发生在行中os.write().