MemoryFile class of any use?

I planned to use shared memory between activity and service in a separate process to transfer large content between them.

For this purpose, I read every information I found on a MemoryFile, and how to transfer it between activity and, in particular, this stackoverflow entry that uses MemoryFile in android .

But I can not call getParcelFileDescriptor (using the solution described) on my Android version 4.xx. It seems that the method no longer exists.

However, I came up with the following code to send ParcelFileDescriptor to my service (think of it as pseudo code, but this is actually ruboto code):

shm = MemoryFile.new("picture", 1000)
f = shm.getFileDescriptor() 
p = ParcelFileDescriptor.dup( f)

b = Bundle.new()
b.putParcelable( "shm", p)
msg.setData( b)
service.send( msg)

, , .

( java) :

 Parcelable p = msg.getData().getParcelable("shm");
 ParcelFileDescriptor shm = (ParcelFileDescriptor) p;
 FileDescriptor f = shm.getFileDescriptor();

 if( f.valid()) {
     FileInputStream in = new FileInputStream( f);
     String s = readString( in); // this fail!
}

, f , Discriptor, : java.io.IOException: : EINVAL ( )

:

public String readString(InputStream inputStream) throws IOException {
BufferedReader r = new BufferedReader(new InputStreamReader(inputStream));
String s = r.readLine();
return s;
}

, :

  • ? ( )
  • MemoryFile #getParcelFileDescriptor ?

, ...

JNI , .

+4
1

MemoryFile Android 4.0.4 shm.getFileDescriptor() ParcelFileDescriptor.dup(f), , , - . , , . ( ) InputStream.read(buffer).

0

All Articles