Android Code Snippet Flexible share INTENT

Hello, everyone.

After browsing the forum for a long time I am attaching the code of my INTENT that I can use to share by e-mail, WhatsApp and other applications.

It supports subject, text, an attachment and even an email.

For me the ideal would be to be able to add a phone and that applications like WhatsApp use this data to communicate directly without having to search for it.

Comments Welcome

B4X:
Dim shareINT As Intent
Dim dr,fn,rut as String
Dim asu,men,ema as String

dr = File.DirDefaultExternal
fn = "sample.png"
asu = "TEST"
men = "This is my INTENT"
ema = "[email protected]"

shareINT.Initialize(shareINT.ACTION_SEND, "")
shareINT.SetType("image/jpg")
' if file is shared
If (fn <> "") Then rut = cfpURI(dr, fn)
If (rut <> "") Then shareINT.PutExtra("android.intent.extra.STREAM",  rut)
If (asu <> "") Then shareINT.putExtra("android.intent.extra.SUBJECT", asu)
If (men <> "") Then shareINT.putExtra("android.intent.extra.TEXT", men)
If (ema <> "") Then shareINT.PutExtra("android.intent.extra.EMAIL",  Array As String(ema))
 
StartActivity(shareINT)


Sub cfpURI(Dir As String, FileName As String) As Object
    Dim FileProvider As JavaObject
    Dim context As JavaObject
    context.InitializeContext
    FileProvider.InitializeStatic("android.support.v4.content.FileProvider")
    Dim f As JavaObject
    f.InitializeNewInstance("java.io.File", Array(Dir, FileName))
    Return FileProvider.RunMethod("getUriForFile", Array(context, Application.PackageName & ".provider", f))
End Sub
 
Top