Android Question How to insert and extract mutliple file/types in an intent

JohnC

Well-Known Member
Licensed User
I am currently embedding an image ("stream") into an intent that is used to create a new shortcut using this code:
B4X:
shortcutIntent.SetType("image/*")
shortcutIntent.PutExtra("android.intent.extra.STREAM", image.bmp)
(note: I need to embed the actual file data into the intent and not a uri reference because of various project requirements)

Then when the shortcut is used to launch my app, I extract the image data using this code:
B4X:
Dim r As Reflector
r.Target = StartIntent
Dim bmp As Bitmap = r.RunMethod2("getParcelableExtra", "android.intent.extra.STREAM", "java.lang.String")
But I would also like to add a sound file (.wav) into the same intent, so how could I embed both media files/types into the same intent?

I ask because the ".SetType("image/*")" method and the "PutExtra("android.intent.extra.STREAM") method don't seem to have any type of "index" parameter to specify which "Settype" is associated with each "extra.stream". So, it gives me the impression that you can only embed one media/file in an intent.

Is there a way I can embed multiple media types and/or multiple files (of the same media type), and then how would I extract each one?
 

emexes

Well-Known Member
Licensed User
Does using a (single) List or Array of multiple Extras work?

eg something like:
B4X:
Dim LotsaStuff() As Object = Array As Object(ExtraPicture, ExtraSound, ExtraVideo)

shortcutIntent.SetType("image/*")
shortcutIntent.PutExtra("android.intent.extra.STREAM", LotasStuff)
and then on the receiving side:
B4X:
Dim r As Reflector
r.Target = StartIntent
Dim LotsaStuff() As Object = r.RunMethod2("getParcelableExtra", "android.intent.extra.STREAM", "java.lang.String")    'presumably .String should be .Array or similar
Dim bmp as Bitmap = LotsaStuff(0)
 
Top