Android Question How to share a video file launching another app

Javier Alonso

Member
Licensed User
Longtime User
Hello,

I wish to share a video file with dropbox, whatsapp or whatever app the user may choose. It is easy when sharing a text, but not a file. I am trying the following codr:

Dim i As Intent
i.Initialize(i.ACTION_SEND, "")
i.SetType("video/mp4")
i.PutExtra("android.intent.extra.STREAM", Url)
i.PutExtra("android.intent.extra.SUBJECT", "Share video:")
i.WrapAsIntentChooser("Share video:")
StartActivity(i)

Where Url points to the video file, named 00001.mp4, and I have checked that the file exists and is in a folder in the external SD card (accesible by the other apps).

The menu with the installed apps is shown, but the apps fail to receive the file. Help, please!
 

Javier Alonso

Member
Licensed User
Longtime User
Still not. I am using a subfolder of DirRootExternal, the expression you suggest resolves to "file:///storage/emulated/0/Slide2Show/1074.mp4". Gmail opens a new email but throws an error like "The file cannot be attached" (or similar, my device do not run in English). I have also tried to place the file in the root folder, or change the syntax to "file://storage/emulated/0/Slide2Show/1074.mp4" just in case, but I got nothing.

If I just want to play the video, a similar code works fine:
Dim i As Intent
i.Initialize(i.ACTION_VIEW, Uri)
i.SetType("video/mp4")
i.PutExtra("android.intent.extra.STREAM", Url)
i.PutExtra("android.intent.extra.SUBJECT", "My Video")
i.WrapAsIntentChooser("Play video:")
StartActivity(i)

But not if I want to share it. What am I missing? Any suggestions?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this code:
B4X:
Dim i As Intent
i.Initialize(i.ACTION_SEND, "")
i.SetType("*/*")
Dim jo As JavaObject = i
Dim uri1 As Uri 'ContentResolver library
uri1.Parse("file://" & File.Combine(File.DirRootExternal, your File))
jo.RunMethod("putExtra", Array("android.intent.extra.STREAM", uri1)) 'put a parcelable object
i.PutExtra("android.intent.extra.SUBJECT", "My Video")
StartActivity(i)
 
Upvote 0
Top