Problem attaching a file into an e-mail

drmover

Member
Licensed User
Longtime User
Hello,

I am having a problem attaching a file into an e-mail.
My code (see below) is working fine on a my phone but when I run it on a tablet the attachment is not being selected even though the file exists and I can select it manually.

Dim SendReport As Email
File.WriteString (File.DirDefaultExternal, "JobAttachment.html", "Test")
SendReport.To.Add("[email protected]")
SendReport.Subject = "Test"
SendReport.Body = "See attachment"
SendReport.Attachments.Add(File.Combine(File.DirDe faultExternal, "JobAttachment.html"))
StartActivity(SendReport.GetIntent)

What should I do? Any ideas?

Thank you,
Elad.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Seems like some devices do not support this method.
You can try something like:
B4X:
Dim Intent1 As Intent
Uri="file://"&File.Combine(File.Combine(File.DirRootExternal,"  cpbackups"),"file.zip")
Intent1.Initialize(Intent1.ACTION_SEND,"")
Intent1.PutExtra("android.intent.extra.SUBJECT","file.zip")
Intent1.PutExtra("android.intent.extra.STREAM",Uri  )
Intent1.SetType("application/zip")
Intent1.PutExtra("android.intent.extra.TEXT","Message Text")
StartActivity(Intent1)
 
Upvote 0

drmover

Member
Licensed User
Longtime User
Did not work...

Hello Erel,

Thank you for your reply but it did not work...

Any other ideas or directions I should try?

Thanks,
Elad.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please try the updated Phone library and see if it fixes this issue. The Intent created is simpler if there is only one attachment.
Example:
B4X:
    Dim ei As Email
    ei.To.Add("[email protected]")
    ei.Body = "mmmm"
    ei.Subject = "aaaaa"
    ei.Attachments.Add(File.Combine(File.DirRootExternal, "1.jpg"))
    StartActivity(ei.GetIntent)
It should show v1.41 in the libraries tab.
 
Upvote 0

drmover

Member
Licensed User
Longtime User
Thank you... work like a charm.

Hello Erel,

Thank you very much - updating the phone library solved this issue.

I have two quick questions regarding this issue:
1. How can I make sure I have the latest libraries?
2. Is there a way to send HTML in the E-Mail instead of as attachment?

Thank you for your great help,
Elad.
 
Upvote 0

drmover

Member
Licensed User
Longtime User
Using GetHtmlIntent

Hello Erel,

Thank you for your reply.

I am trying to send HTML in the e-mail's body by using the new method GetHtmlIntent but when doing so the body remains in plain text.

Can you please drop some code example how to do it?

Thank you,
Elad.
 
Upvote 0

drmover

Member
Licensed User
Longtime User
Reply

Yes it is in HTML format.

On the WebView it's all look very good but when I set up the same in the email's body it comes as Plain Text.

I am sending you the e-mail as I am getting it from the device.

Thank you,
Elad.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Are you sending it with Gmail? It should be formatted already in the mail client application.
You can try this code for an example:
B4X:
Sub Activity_Create(FirstTime As Boolean)
Dim e As Email
e.Body = "<b>hello</b> world."
StartActivity(e.GetHtmlIntent)
End Sub

20110615_1.png
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
Upvote 0
Top