I need to send some data to a C program from my app in Android, and I think about using pipes. I read that Java can access to existing pipes (and open them as if it\'s a normal
Ok, I tried to fix the problem with the most stupid app that exists. You can find this one as a gist on github.
So far, I discover this :
/data/data/package.full.name/
)ls -l -a
on /data/data/
and have a look to the group name).DO NOT FORGET : You can't actually write in the pipe until someone is listening at the other side. So if you test the file I posted on github, you will have that kind of logcat result.
I/ActivityManager( 220): Start proc fr.stackr.android.upt for activity fr.stackr.android.upt/.UnixPipeActivity: pid=1359 uid=10048 gids={}
I/UPIPE ( 1359): Attempt started
W/ActivityManager( 220): Launch timeout has expired, giving up wake lock!
W/ActivityManager( 220): Activity idle timeout for HistoryRecord{4643c8b8 fr.stackr.android.upt/.UnixPipeActivity}
Here, the system pause because nothing happens… Then I run cat v_pipe
on the phone.
V/UPIPE ( 1359): SEND :: Try to write the first paragraph ....
V/UPIPE ( 1359): SEND :: Bip
V/UPIPE ( 1359): Flushing...
V/UPIPE ( 1359): SEND :: Bip post flush
V/UPIPE ( 1359): Closing…
I/UPIPE ( 1359): Attempt ended
That's done.
closing : when I close the OutputStreamWriter
, the listening side (ie cat
) ends.
If I commment the line, cat
will still wait for input.
flushing : seems to be important if you intent to get something without calling close.
Carriage Return : Use \n
.
I think you can use ParcelFileDescriptor.createPipe()
It will return an array of pipe for read and write. For more information, visit the developers website.