Good evening to all of you,
I am trying to embed an image in an e-mail I create with html but it does not seem to care at all and it does not add it. I always see a square with the letters "OBJ" inside, in all e-mail apps. What do you thing might be happening? I have Android 14. Here is my code - the sub for the image encoder is copied and changed from an other member of the forum:
I am trying to embed an image in an e-mail I create with html but it does not seem to care at all and it does not add it. I always see a square with the letters "OBJ" inside, in all e-mail apps. What do you thing might be happening? I have Android 14. Here is my code - the sub for the image encoder is copied and changed from an other member of the forum:
B4X:
Private Sub SendEmail(sJSON As String)
Dim email As Email
email.To.Add("")
email.Subject = "This the subject"
email.Body = GetHTMLForEmail(sJSON)
StartActivity(email.GetHtmlIntent)
End Sub
Private Sub GetHTMLForEmail(sJSON As String) As String
Dim sHTML As String = $"
<center>
<img alt="Top image" src=CHANGETOIMGTOP style="max-width:1402"></img>
</center>
"$
sHTML = sHTML.Replace("CHANGETOIMGTOP", AddEmbededImageInMail("", "imgtop.png", Null, False))
Log(sHTML)
Return sHTML
End Sub
Public Sub AddEmbededImageInMail(strImagePathOrNullIfB4XBitmap As String,strImageNameOrNullIfB4XBitmap As String, bmpOrNullIfNoB4XBitmapIsUsed As B4XBitmap, ReturnIMGTag As Boolean) As String
Dim Bytes() As Byte
Dim su As StringUtils
If bmpOrNullIfNoB4XBitmapIsUsed.IsInitialized = False Then
'The path of the image.
Dim strPath As String
If strImagePathOrNullIfB4XBitmap.Trim = "" Then
strPath = File.DirAssets 'ie. ..../Files
Else
strPath = strImagePathOrNullIfB4XBitmap
End If
Bytes = File.ReadBytes(strPath,strImageNameOrNullIfB4XBitmap) 'Read the image into an array of bytes.
Else
Bytes = ImageToBytes(bmpOrNullIfNoB4XBitmapIsUsed)
Log(Bytes.Length)
End If
Dim strImageBase64 As String
strImageBase64 = su.EncodeBase64(Bytes) 'Now Convert our Image to Base64 string so that it can be directly embedded into the HTML.
'Prepare the image HTML 'src' property which will contain the Image data as Base64.
Dim strImageSource As String = """" & "data:image/png;base64, " & strImageBase64 & """" ' "data:image/png;base64, abc123//444553"
If ReturnIMGTag Then
Dim strHTML As String = ""
strHTML = "<img alt=""Picture"" src=" & strImageSource & " " & "/>"
Return strHTML
Else
Return strImageSource
End If
End Sub
Public Sub ImageToBytes(Image As B4XBitmap) As Byte()
Dim out As OutputStream
out.InitializeToBytesArray(0)
Image.WriteToStream(out, 100, "PNG")
out.Close
Return out.ToBytesArray
End Sub