Mailto: and phones

gehrlekrona

Member
Licensed User
Longtime User
I have been searching and trying to find anything that could show me how to send an email by clicking on an email link in Webview, but haven't been able to. I have read about OverrideURL but doesn't figure it out
I would also like to know how yu can click on a link (?) with a phone number so you can call straight from the web page.

It should be pretty simple I would guess, but I haven't been able to figure it out

Anybody who can help?
 

admac231

Active Member
Licensed User
Longtime User
Basically OverrideURL is the sub that's called before the page is loaded. So the order of operations is:

Link is pressed in webview -> OverrideURL -> New url is loaded -> PageFinished

So what you want to do is intercept all hyperlinks that start with "mailto:" within the OverrideURL sub.

This is easily done, like so:
B4X:
Sub OverrideURL (Url As String)
   If url.IndexOf("mailto:") > -1 Then
      'Do what you want with the mailto link
   End If
End Sub
So now that you know the link pressed is a mailto link you can work with it.

Use the phone library (that is, check the "Phone" library in the IDE) for Email like so:
B4X:
Dim Message As Email
Message.To.Add(url)
Message.Body = "Email body"
StartActivity(Message.GetIntent)

Bare in mind you need to strip the "mailto:" part from the Url string as well:
B4X:
url.replace("mailto:","")

Altogether now!
B4X:
Sub OverrideURL (Url As String)
   If url.IndexOf("mailto:") > -1 Then
      Dim Message As Email
      Message.To.Add(Url.replace("mailto:",""))
      Message.Body = "Email body"
      StartActivity(Message.GetIntent) 
   End If
End Sub

I don't have an answer for the numbers question although I imagine the solution will be quite similar.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Hi.

Don't forget that the OverrideUrl Sub should return a Boolean value to indicate whether the URL has been handled by your activity or not:

Basic4android - Views (Core)

So if your activity has handled a mailto link then OverrideUrl should return a True value otherwise it should return a False value.

Martin.
 
Upvote 0

gehrlekrona

Member
Licensed User
Longtime User
Mailto: OverrideURL

Thanks.
This is how I made it work. Thought I'd share it in OverrideURL.

Dim p As PhoneCalls
Dim Message As Email

If Url.Contains("@") Then
' send email

Message.To.Add(Url)
' Message.Attachments.Add(File.Combine(File.DirRootExternal, "SomeFile.txt"))
Message.Subject = "Your Ad at PawsitesOnline.com"
StartActivity(Message.GetIntent)

Else

StartActivity(p.Call(Url))

End If
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…