Hello guys,
I am using this class provided in this :
https://b4x.com/android/forum/threads/class-fileprovider-share-files.97865/#post-616995
to send email with attachment.
I am only add a code from that example to add email body.
Here is my changed code
Sub btnSendEmail_Click
Dim FileName As String = "b4a.png"
'copy the shared file to the shared folder
File.Copy(File.DirAssets, FileName, Starter.Provider.SharedFolder, FileName)
Dim email As Email
email.To.Add("aaa@bbb.com")
email.Subject = "subject"
email.Body = "This is a test" 'This is the added code
email.Attachments.Add(Starter.Provider.GetFileUri(FileName))
email.Attachments.Add(Starter.Provider.GetFileUri(FileName)) 'second attachment
Dim in As Intent = email.GetIntent
in.Flags = 1 'FLAG_GRANT_READ_URI_PERMISSION
StartActivity(in)
End Sub
This was tested on Android Oreo 8.0 with B4A 8.30 on the real device.
And this is the strange thing :
1. After install on device , first clicked on Send Mail -> failed to load attachment
2. Second clicked, without quit application -> worked fine
3. Quit application then clicked again Send mail -> still worked fine
4. After it worked fine, testing again and again, always worked fine.
5. Uninstall app, then install again, first clicked -> failed to load attachment, second clicked and so on -> worked fine
I can reproduce the behavior by install and uninstall app.
Another thing, on Lolipop, there is a shared folder created under DirInternal (i think), but on oreo, there wasn't such folder, where is shared folder created under Oreo?
Any idea, why this is happen ?
Thanks in advance.