3

Is it possible to pass Socket/FileDescriptor from one activity to other activity in other application? I tried using Intent but got

java.lang.IllegalArgumentException: File descriptors passed in Intent

Please help!

eckes
  • 64,417
  • 29
  • 168
  • 201
Sangmin Lee
  • 31
  • 1
  • 4

2 Answers2

0

Sure you can - using content providers. Yo have to create your own content provider and override its method openFile. Read here, for instance: http://www.grokkingandroid.com/handling-binary-data-with-contentproviders/

user983447
  • 1,598
  • 4
  • 19
  • 36
-1

The short answer is: probably no, but...

Activity in the other application run in the other process. I believe, there is no ability to pass Socket or FileDescriptor from one process to another - neither in Java nor in Android. But it's possible in Linux using UNIX sockets and SCM_RIGHTS: man unix(7), cmsg(3). Since Android is based on Linux kernel, probably you can write this functionality in C and pass it to your Java code with JNI (see Android NDK). Possibly, you also have to implement your own versions of Socket and FileDescriptor. Summing up, I think you really don't want to do it all. Probably the best way - to review your task and find another, simpler solution.

Just in case: inside the one application you can reuse Sockets and FileDescriptors freely. For example, using static members and some kind of synchronization Intents.

praetorian droid
  • 2,989
  • 1
  • 17
  • 19
  • 3
    This is blatantly incorrect. [A Java binding to SCM_RIGHTS](https://developer.android.com/reference/android/net/LocalSocket.html) has existed since earliest Android version. Android own IPC, Binder, [also had descriptor-passing functionality](https://developer.android.com/reference/android/os/Parcel.html#writeFileDescriptor%28java.io.FileDescriptor%29) since earliest releases of platform. – user1643723 Apr 25 '16 at 16:45