I want to convert the filedescriptor (int) obtained from native to filedescriptor (Java object)
//native
int fd = open(......);
Why doesn't example 1 work? Maybe in theory?
//eg 1:
FileDescriptor mFd = ParcelFileDescriptor.adoptFd(fd).getFileDescriptor();
//eg 2:
FileDescriptor mFd = new FileDescriptor()
Method setFd = FileDescriptor.class.getDeclaredMethod("setInt$", int.class);
setFd.setAccessible(true);
setFd.invoke(mFd, fd);
Microsoft:
Take ownership of a raw native fd in to a new ParcelFileDescriptor.
C#
[Android.Runtime.Register("adoptFd", "(I)Landroid/os/ParcelFileDescriptor;", "")]
public static Android.OS.ParcelFileDescriptor? AdoptFd (int fd);
Parameters fd Int32 The native fd that the ParcelFileDescriptor should adopt.
Returns
ParcelFileDescriptor
Returns a new ParcelFileDescriptor holding a FileDescriptor for the given fd.
Attributes RegisterAttribute