Android Question [B4XPages] How to Send to... / share?

vecino

Well-Known Member
Licensed User
Longtime User
Hi, I am showing the user a window with a list of sound, video and audio files.
I want the user to click on any of them and be able to "send to / share" and "gmail, telegram, whatsapp, protonmail, etc." is displayed.
Summarizing, my doubt is:
When the user selects "share", how do I show those programs so he can choose one of them?
Thank you.
 
Solution
B4X:
Dim FileToSend As String = "card.jpg"
  
Dim i As Intent
i.Initialize(i.ACTION_SEND,"")
i.SetType("image/jpg")   'JPEG
'i.SetType("video/*")  'MP4
i.SetComponent("")  'empty: show all the programs that can be share the image, video...

i.PutExtra("android.intent.extra.STREAM", Starter.Provider.GetFileUri(FileToSend))

asales

Expert
Licensed User
Longtime User
B4X:
Dim FileToSend As String = "card.jpg"
  
Dim i As Intent
i.Initialize(i.ACTION_SEND,"")
i.SetType("image/jpg")   'JPEG
'i.SetType("video/*")  'MP4
i.SetComponent("")  'empty: show all the programs that can be share the image, video...

i.PutExtra("android.intent.extra.STREAM", Starter.Provider.GetFileUri(FileToSend))
 
Upvote 1
Solution

vecino

Well-Known Member
Licensed User
Longtime User
Hi, thanks, I have tried and it doesn't work, it doesn't do anything, it doesn't show any message and it doesn't show any error, nothing at all.
I am using this code:
B4X:
Sub SendTo( cFile As String )
    '  copy to share dir
    File.Copy(ShCode.cDirMedia,cFile, ShCode.cDirShared,cFile)
    '  share
    Dim i As Intent
    i.Initialize(i.ACTION_SEND,"")
    i.SetType("image/png")
    i.SetComponent("")
    i.PutExtra("android.intent.extra.STREAM",Starter.Provider.GetFileUri(cFile))  
End Sub
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
This was missing:
StartActivityForResult( i )

I don't know if it's correct to use that with B4XPages, or maybe you have to use something else.
Thanks.

B4X:
Sub SendTo( cFile As String )
    '  copy to share dir
    File.Copy(ShCode.cDirMedia,cFile, ShCode.cDirShared,cFile)
    '  share
    Dim i As Intent
    i.Initialize(i.ACTION_SEND,"")
    i.SetType("image/png")
    i.SetComponent("")
    i.PutExtra("android.intent.extra.STREAM",Starter.Provider.GetFileUri(cFile)) 
    StartActivityForResult( i )
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Important example: https://www.b4x.com/android/forum/threads/class-fileprovider-share-files.97865/#content

SS-2018-10-03_15.03.31.png
 
Upvote 1
Top