Android Question Screenshot to Email

Marcelo Herrera

Member
Licensed User
Longtime User
Hi,

I am working on an app and I want to create a button within the same screen that once it's clicked, it takes a snapshot and sends it to an specific email account. Any Ideas on how to do this?

I downloaded the NET library, however, I'm not sure in how to do this, since I want to use my companies server to send the email. It would be like sending an email to my self (i.e from my@email.com to my@email.com).

Let me know if this is possible.
Thanks
 

DonManfred

Expert
Licensed User
Longtime User
Search the forum. You´ll find code to do a snapshot and save it to disc. And you´ll find code to send a picture via mail.
I´m sure you have not searched.

Taking Screenshot can be done with
Please note that i have not tested it; just found after a quick search
Edit: have it tried and works for me
B4X:
Sub Btn1_Click
   Dim Obj1, Obj2 As Reflector
   Dim bmp As Bitmap
   Dim c As Canvas
   Obj1.Target = Obj1.GetActivityBA
   Obj1.Target = Obj1.GetField("vg")
   bmp.InitializeMutable(Activity.Width, Activity.Height)
   c.Initialize2(bmp)
   Dim args(1) As Object
   Dim types(1) As String
   Obj2.Target = c
   Obj2.Target = Obj2.GetField("canvas")
   args(0) = Obj2.Target
   types(0) = "android.graphics.Canvas"
   Obj1.RunMethod4("draw", args, types)
   Dim Out As OutputStream
   Out = File.OpenOutput(File.DirRootExternal, "Test.png", False)
   bmp.WriteToStream(out, 100, "PNG")
   Out.Close
End Sub

See Net-Tutorial for an example of sending email

PS: I SEARCHED the forum... It takes two minutes to find this both
 
Last edited:
Upvote 0

Marcelo Herrera

Member
Licensed User
Longtime User
What I have right now is this.... but i get a message saying that the message was not sent.

Sub send_Click
Dim Obj1, Obj2 As Reflector
Dim bmp As Bitmap
Dim c As Canvas
Obj1.Target = Obj1.GetActivityBA
Obj1.Target = Obj1.GetField("vg")
bmp.InitializeMutable(Activity.Width, Activity.Height)
c.Initialize2(bmp)
Dim args(1) As Object
Dim types(1) As String
Obj2.Target = c
Obj2.Target = Obj2.GetField("canvas")
args(0) = Obj2.Target
types(0) = "android.graphics.Canvas"
Obj1.RunMethod4("draw", args, types)
Dim Out As OutputStream
Out = File.OpenOutput(File.DirRootExternal, "Someimage.png", False)
bmp.WriteToStream(Out, 100, "PNG")
Out.Close

SMTP.Initialize("1.serever.com", 110, "myemail@email.com", "xxxxxx", "SMTP")
SMTP.StartTLSMode = True

SMTP.To.Add("myemail@email.com")
SMTP.Subject = "This is the subject"
SMTP.Body = "This is the message body."
SMTP.AddAttachment(File.DirRootExternal, "Someimage.png")
SMTP.Send

End Sub
Sub SMTP_MessageSent(Success As Boolean)
Log(Success)
If Success Then
ToastMessageShow("Message sent successfully", True)
Else
ToastMessageShow("Error sending message", True)
Log(LastException.Message)
End If
End Sub
 
Upvote 0
Top