Android Question WhatsApp link works in browser but not inside WebView – how to fix?

Adamdam

Active Member
Licensed User
Longtime User
I’m facing an issue with a WebView implementation in my app.


I have a PHP page hosted on a server that includes a link to open WhatsApp (for sending a message). When I open this page in a normal mobile browser, it works perfectly—it opens WhatsApp and prepares the message as expected.


However, when I load the same PHP page inside a WebView in my app, clicking the WhatsApp link does nothing (or it doesn’t open WhatsApp).


What I’ve tried:


  • The same URL works fine outside WebView (in Chrome or other browsers)
  • The issue only happens inside WebView

Question:
How can I enable WebView to properly open WhatsApp links (e.g., https://wa.me/... or intent:// links)?
Do I need to handle this differently inside WebView?
 

zed

Well-Known Member
Licensed User
B4A's WebView cannot automatically open WhatsApp links. You need to intercept the URLs (wa.me, whatsapp://, intent://) in ShouldOverrideUrl and manually launch an Android intent.

A WebView does not handle external URL schemes.

Try this
B4A:
Sub WebView1_OverrideUrl (Url As String) As Boolean
    If Url.StartsWith("https://wa.me/") Or Url.StartsWith("whatsapp://") Then
        OpenWhatsApp(Url)
        Return True
    End If

    WebView1.LoadUrl(Url)
    Return True
End Sub

Sub OpenWhatsApp(Url As String)
    Try
        Dim i As Intent
        i.Initialize(i.ACTION_VIEW, Url)
        StartActivity(i)
    Catch
        ToastMessageShow("WhatsApp is not installed", True)
    End Try
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
How can I enable WebView to properly open WhatsApp links (e.g., https://wa.me/... or intent:// links)?
Using the solution in #2 will open the link in a browser. Not in your webview.

So the real anser is no, it does not work in a webview.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…