Android Question ( Solved) Auto-fill SendTo, Subject not working with Attachments

anOparator

Active Member
Licensed User
Longtime User
I auto-fill the To, Subject, and Body fields, and can send the email.
When I add the attachment Sub, 'ShareMultipleImages', these fields no longer auto-fill but all the attachments are listed.
I enter the To, Subject, and Body fields manually and finally send.

How can I get auto-fill and have the attachments at the same time?
B4X:
Sub savTxt_Click
    ' with Next line, e.To, e.Subject, and e.Body are Not auto-filled but I have Attachments.
    ' w/o Next line, e.To, e.Subject, and e.Body are auto-filled but No Attachments.
   ShareMultipleImages(images, Starter.strSharedFolder)
   Dim e As Email
   e.To.Add(EditText1.text)
   e.Subject = "testing23"
   e.Body = "test23"
   StartActivity(e.GetIntent)
    '  ShareMultipleImages(images, Starter.strSharedFolder)  
End Sub
ps: I think I'm using the Phone library without an Intent, is this correct?
thanks in advance
 

Attachments

  • chg.bas
    2.4 KB · Views: 156

anOparator

Active Member
Licensed User
Longtime User
So I messed up scaling down the project w/o making a backup, and had error:
B4X:
:chg,2490375
java.lang.reflect.InvocationTargetException

Re-read the ShareFileWithFileProvider sample, updated the module and got it working with:
B4X:
Sub savTxt_Click
   Log(" start savTxt")
   '**  Makes available Email client and Save to Drive only
   Dim e As Email
   e.To.Add(EditText1.text)
   e.Subject = ""
   e.Body = "test"
   e.Attachments.Add(CreateFileProviderUri(Starter.shared, "1.txt"))
   e.Attachments.Add(CreateFileProviderUri(Starter.shared, "2.txt"))
   e.Attachments.Add(CreateFileProviderUri(Starter.shared, "3.txt"))
   StartActivity(e.GetIntent)
End Sub
and
B4X:
Sub CreateFileProviderUri (Dir As String, FileName As String) As Object
   Log("start CreateFileProviderUri")
   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

Am happy and sleepy now, B4A.
 

Attachments

  • email1.txt
    1.2 KB · Views: 167
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…