Share with Email

FabioG

Active Member
Licensed User
Longtime User
Hello,

How can I share a file using a mail client?
I wish I could do as shown in the picture.

thanks
 

Attachments

  • Screenshot_2013-02-10-12-03-48.jpg
    Screenshot_2013-02-10-12-03-48.jpg
    73.4 KB · Views: 298

FabioG

Active Member
Licensed User
Longtime 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
 
Upvote 0

FabioG

Active Member
Licensed User
Longtime 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", "[email protected]")
   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
 
Upvote 0

FabioG

Active Member
Licensed User
Longtime 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", "[email protected]")
      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
 
Upvote 0

Mahares

Expert
Licensed User
Longtime 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
 
Upvote 0

FabioG

Active Member
Licensed User
Longtime 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
 
Upvote 0

gvinetweb

Member
Licensed User
Longtime 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:
Upvote 0
Top