Override mailto: force close

canalrun

Well-Known Member
Licensed User
Longtime User
Hello,
I am trying to override a mailto: in the URL for a WebView. I have included my small test program below. Each time I run this, with either 1.7 or 1.8 just after the StartActivity I get a Force Close, but the default e-mail client does open. Am I doing something simple wrong?

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   
    Dim LayVal As LayoutValues
   Dim wv1 As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
  Dim s As String

  LayVal = Activity.LoadLayout("l1")
  
  wv1.Left = 0
  wv1.Top = 0
  wv1.Width = 100%x
  wv1.Height = 100%y
  
  s = File.GetText(File.DirAssets, "fsHlp.html")
  wv1.LoadHtml(s)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub wv1_OverrideURL (Url As String)
'
' The URL is: mailto:[email protected]?Subject=MyTest
'
  If (Url.IndexOf("mailto:") > -1) Then
    Dim Intent1 As Intent
    Intent1.Initialize(Intent1.ACTION_VIEW, Url)
    StartActivity(Intent1)
    Return(True)
  End If
End Sub

Thanks,
Barry.
 

canalrun

Well-Known Member
Licensed User
Longtime User
Maybe is this line:

B4X:
Return(True)

It should be:

B4X:
Return True

Thank you for your reply. I tried your suggestion and I still get the same crash – Force Close.

I attached my tiny sample project. Maybe it is just my phone and will work properly for others, but I saw one other post with this same problem and no solution.

Thanks,
Barry.
 

Attachments

  • MailTst.zip
    6.8 KB · Views: 178
Upvote 0

NJDude

Expert
Licensed User
Longtime User
The problem was in this routine, you were missing the AS BOOLEAN.

B4X:
Sub wv1_OverrideURL(Url As String) As Boolean '<--- You were missing this

      If Url.IndexOf("mailto:") > -1 Then

         Dim Intent1 As Intent

         Intent1.Initialize(Intent1.ACTION_VIEW, Url)

         StartActivity(Intent1)

         Return True

      End If

End Sub

You have to change the word "subject" to all lower case on your HTML if you want the subject line to show up.
 
Last edited:
Upvote 0

canalrun

Well-Known Member
Licensed User
Longtime User
The problem was in this routine, you were missing the AS BOOLEAN.

B4X:
Sub wv1_OverrideURL(Url As String) As Boolean '<--- You were missing this
      If Url.IndexOf("mailto:") > -1 Then
         Dim Intent1 As Intent
         Intent1.Initialize(Intent1.ACTION_VIEW, Url)
         StartActivity(Intent1)
         Return True
      End If
End Sub

You have to change the word "subject" to all lower case on your HTML if you want the subject line to show up.

Thank you so much. Works like a champ now.

Barry.
 
Upvote 0
Top