Android: write failed: EPIPE (Broken pipe) Error on write file
Asked Answered
E

2

19

I was trying to take screenshot of the Android screen programatically. I had done the following code:

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)

Please can someone help? I had already checked the other posts and I dont find anything solving my issue.


EDIT:

Please note, the Error happens in the line os.write().

Edwinedwina answered 12/7, 2013 at 12:54 Comment(3)
Do you have root permissions on your device?Dryasdust
@Alex- I was just running it on the Emulator. And in one of the post, I found, i dont have to have root permission. May be it is wrong. Please can you help me how to get that root permission on the emulator?Edwinedwina
You are trying to use a system command from /system/bin. I assume you'd need root permissions to invoke that on the emulator. But you can try this method of taking a screenshot: #2662036Neighborly
D
10

EPIPE issue usually happens when you either try to execute command which needs root permissions (getRuntime().exec) in your case on the device without it or run several root commands simultaneously. If you work on the emulator and need to root it I think you you can try this while the emulator is running:

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

Here http://abd-tech.blogspot.com/2011/05/test-root-apps-on-android-emulator.html more detail explanation.

Dryasdust answered 12/7, 2013 at 13:4 Comment(10)
Thanks for the reply. Please could you let me know how I can use this apk in the code? And I get the error on os.write.Edwinedwina
@HariprasauthRamamoorthy See my edits.I suggested more clear wayDryasdust
Thank you for that again. I am just trying to execute these commands from the command prompt and it just seems to hang. Have you tried these before? Will it take a lotoftime to execute one line?Edwinedwina
@HariprasauthRamamoorthy It's rather strange. Of course I tried it and not one time. Everything worked good. Try to restart adb.Dryasdust
now it works.. I have now install superuser - su.. Shall I follow the same link?Edwinedwina
Please could you possibly post the SuperUser.apk somewhere? The content in the link you mentioned has been removed.Edwinedwina
@HariprasauthRamamoorthy Of course. Here is a link where you can download it walkthroughapk.com/apps/…Dryasdust
sorry Alexander. Even there it has been removed. Can you post one here? please.Edwinedwina
No. Its still not working. :( I had installed the superuser in emulator. Then tried the same, now, it doesnt give any errors, but, the file is also not getting created..Edwinedwina
am getting an error of cannot stat 'su' no such file (or) directory. How to resolve this?Goal
S
0

The problem is that your app does not have system permissions to access the surface flinger (which uses screen buffer and hw decoder to render your video file). In order to have these permissions you have to build (and sign) your app as a system app and locate it at the system/priv-app folder. In addition to that you have to add the following permission to this system app:

<manifest package="com.yourapp.demo"
    android:versionCode="1"
   coreApp="true"
    android:sharedUserId="android.uid.media"
    android:versionName="1.0" xmlns:android="http://schemas.android.com/apk/res/android">

note the coreApp="true" android:sharedUserId="android.uid.media" parts.

and you will have to add <uses-permission android:name="android.permission.ACCESS_SURFACE_FLINGER" /> permission.

please checkout this as well: Permission denial: Can't access the SurfaceFlinger

Sawn answered 28/6, 2015 at 12:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.