如何通过C#/Xamarin中的Webview链接调用whatsapp? [英] How to call whatsapp through a link from webview in C#/Xamarin?
本文介绍了如何通过C#/Xamarin中的Webview链接调用whatsapp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
除了Java,我发现了一些例子.
I have found some examples but for java.
链接是:
<a href="whatsapp://send?text=message">
MainPage.xaml.cs:
MainPage.xaml.cs:
public void Webnav_Navigating(object sender, WebNavigatingEventArgs e)
{
string url = e.Url;
if (url.StartsWith("whatsapp://"))
{
// what I need here?
}
}
推荐答案
如果已安装WhatsApp,则可以致电Device.OpenUri
:
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);
}
}
}
这篇关于如何通过C#/Xamarin中的Webview链接调用whatsapp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文