gpt4 book ai didi

Android:写入失败:EPIPE(断管)写入文件时出错

转载 作者:IT老高 更新时间:2023-10-28 23:13:16 29 4
gpt4 key购买 nike

我试图以编程方式截取 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() 行中。

最佳答案

EPIPE 问题通常发生在您尝试在没有它的设备上执行需要 root 权限的命令 (getRuntime().exec) 或同时运行多个 root 命令时。如果您在模拟器上工作并需要对其进行 root,我认为您可以在模拟器运行时尝试此操作:

adb shell mount -o rw,remount -t yaffs2 /dev/block/mtdblock03 /system  
adb push su /system/xbin/su
adb shell chmod 06755 /system
adb shell chmod 06755 /system/xbin/su

这里http://abd-tech.blogspot.com/2011/05/test-root-apps-on-android-emulator.html更详细的解释。

关于Android:写入失败:EPIPE(断管)写入文件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17615412/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com