Reputation: 1568
I have found some examples but for java.
The link is:
<a href="whatsapp://send?text=message">
MainPage.xaml.cs:
public void Webnav_Navigating(object sender, WebNavigatingEventArgs e)
{
string url = e.Url;
if (url.StartsWith("whatsapp://"))
{
// what I need here?
}
}
Upvotes: 5
Views: 1709
Reputation: 74174
If WhatsApp is installed, you can just call Device.OpenUri
:
void WebView_Navigating(object sender, WebNavigatingEventArgs e)
{
var url = e.Url;
if (url.StartsWith("whatsapp://", StringComparison.InvariantCultureIgnoreCase))
{
try
{
Device.OpenUri(new Uri(e.Url));
}
// Can not catch Android exception type in NetStd/PCL library, so hack it...
catch (Exception ex) when (ex.Message.StartsWith("No Activity found to handle Intent", StringComparison.InvariantCulture))
{
// WhatsApp not installed : Android.Content.ActivityNotFoundException: No Activity found to handle Intent
Console.WriteLine(ex);
}
}
}
Upvotes: 6