1

I've just wanted share byte array but when I used "EXTRA_STREAM" it didn't work. Please help me.

            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_SEND);

            if (attachBytes != null) {

                intent.putExtra(Intent.EXTRA_STREAM, byteArray);
                intent.setType(sharingMessageType + "/*");
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            }

            return intent;
propoLis
  • 1,229
  • 1
  • 14
  • 48

1 Answers1

2

The documentation for EXTRA_STREAM states that its value is:

A content: URI holding a stream of data associated with the Intent, used with ACTION_SEND to supply the data being sent.

(emphasis added)

So, the value for your EXTRA_STREAM needs to be a Uri with a content scheme that points to the data that you wish to share. For example, you could use FileProvider to share a file that contains the data that you wish to share.

Regardless, you cannot directly put a byte[] as the value of EXTRA_STREAM and expect it to work with arbitrary apps. The developers of the other apps will be expecting a Uri with a content scheme and will crash when trying to use your byte[], probably with a ClassCastException.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491