Har*_*thy 18 android outputstream file epipe android-permissions
我试图以编程方式截取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().
Ole*_*rov 10
EPIPE问题通常发生在您尝试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
Run Code Online (Sandbox Code Playgroud)
这里http://abd-tech.blogspot.com/2011/05/test-root-apps-on-android-emulator.html更详细的说明.