Share with Email

FabioG

Active Member
Licensed User
I tried with this code, the application allows me to select the mail client, but when it is not loaded to open the attachment and does not compile the object.

How can I fix?

unfortunately I can not use Net library because users must necessarily be able to choose the mail client

thanks

B4X:
Sub Share

   Dim i As Intent
   i.Initialize(i.ACTION_SEND, "")
   i.SetType("text/html")
   i.PutExtra("Intent.EXTRA_EMAIL", "")
   i.PutExtra("Intent.EXTRA_SUBJECT", "the subject")
   i.PutExtra("Intent.EXTRA_STREAM", "file://" & File.DirInternal & "info.zip")
   i.WrapAsIntentChooser("Share Log")
   StartActivity(i)

End Sub
 

FabioG

Active Member
Licensed User
I solved in part with this code but I can not attach the file
and set the email address, but the most important thing for me is being able to attach a file to email

you have suggestions?
thanks


B4X:
Sub Share

   Dim i As Intent
   i.Initialize(i.ACTION_SEND, "")
   i.SetType("text/html")
   i.PutExtra("android.intent.extra.EMAIL", "prova@gmail.com")
   i.PutExtra("android.intent.extra.SUBJECT", "the subject")
   i.PutExtra("android.intent.extra.TEXT", "test")
   i.PutExtra("android.intent.extra.STREAM", "file://" & File.DirInternal & "info.zip")
   i.WrapAsIntentChooser("Share Log")
   StartActivity(i)

End Sub
 

FabioG

Active Member
Licensed User
solved for the attachment


B4X:
Sub Share

File.Copy(File.DirInternal,"info.zip",File.DirRootExternal,"info.zip")
   
      Dim i As Intent
      i.Initialize(i.ACTION_SEND, "")
      i.SetType("text/html")
      'i.PutExtra("android.intent.extra.EMAIL", "prova@gmail.com")
      i.PutExtra("android.intent.extra.SUBJECT", "the subject")
      i.PutExtra("android.intent.extra.TEXT", "test")   
      i.PutExtra("android.intent.extra.STREAM", CreateUri("file://" & File.Combine(File.DirRootExternal,"info.zip")))
      i.WrapAsIntentChooser("Share Log")
      StartActivity(i)


End Sub

Sub CreateUri(uri As String) As Object
    Dim r As Reflector
    Return r.RunStaticMethod("android.net.Uri", "parse", Array As Object(uri), Array As String("java.lang.String"))
End Sub
 

Mahares

Well Known Member
Licensed User
@Fabio: Here is a way to send an email with an attachment while choosing a mail client:
B4X:
Dim MyEmail As Email
Sub EmailFile   'email the file to an individual
   MyEmail.To.Add(emailaddresshere)   'email address
   MyEmail.Subject="This is the file."
    MyEmail.Body="Emailing you the file for today: " & DateTime.Date(DateTime.Now) 
   MyEmail.Attachments.Add(File.Combine(File.DirInternal,  "info.zip"))
   StartActivity(MyEmail.GetIntent)
End Sub
 

FabioG

Active Member
Licensed User
@Fabio: Here is a way to send an email with an attachment while choosing a mail client:
B4X:
Dim MyEmail As Email
Sub EmailFile   'email the file to an individual
   MyEmail.To.Add(emailaddresshere)   'email address
   MyEmail.Subject="This is the file."
    MyEmail.Body="Emailing you the file for today: " & DateTime.Date(DateTime.Now) 
   MyEmail.Attachments.Add(File.Combine(File.DirInternal,  "info.zip"))
   StartActivity(MyEmail.GetIntent)
End Sub
it works perfectly!

thanks
 

gvinetweb

Member
Licensed User
share Facebook tiwetter App opend

Hello, I want to share a text to facebook and twitter applications.

By pressing the button, open the facebook and / or Twitter open the application with text post.

Facebook------------------------
B4X:
Dim i As Intent
Dim pm As PackageManager
Dim mensaje, mensaje2, mensajef As String

mensaje= "Comiendo un subway del día de "& Label3.text
mensaje2= "https://graph.facebook.com/Subway/"
mensajef=mensaje &" "& mensaje2

i = pm.GetApplicationIntent("com.twitter.android")
         
 If i.IsInitialized Then 
        i.Initialize(i.ACTION_SEND, "")
        i.SetType("text/plain")
        'i.PutExtra("text", mensaje)
        i.PutExtra("android.intent.extra.TEXT", mensajef)
         StartActivity(i)   
            
Else
   
      ToastMessageShow("Aplicación no esta instalada", False)
            
End If   
---------------------------

But it does not, just open the blank facebook.
and if it is for twitter, facebook becomes open

Twitter-----------------------------

Dim i As Intent
Dim pm As PackageManager
Dim mensaje, mensaje2, mensajef As String

mensaje= "Comiendo un subway del día de "& Label3.text
mensaje2= "https://graph.facebook.com/Subway/"
mensajef=mensaje &" "& mensaje2

i = pm.GetApplicationIntent("com.facebook.katana")
         
 If i.IsInitialized Then 
        i.Initialize(i.ACTION_SEND, "")
        i.SetType("text/plain")
        'i.PutExtra("text", mensaje)
        i.PutExtra("android.intent.extra.TEXT", mensajef)
         StartActivity(i)   
            
Else
   
      ToastMessageShow("Aplicación no esta instalada", False)
            
End If
----------------------------

Could anyone help me?
 
Last edited:
Top