gpt4 book ai didi

c# - 如何通过 C#/Xamarin 中 webview 的链接调用 whatsapp?

转载 作者:太空宇宙 更新时间:2023-11-03 13:08:11 25 4
gpt4 key购买 nike

我找到了一些示例,但不是针对 java 的。

链接是:

<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?
}
}

最佳答案

如果安装了 WhatsApp,您只需调用 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# - 如何通过 C#/Xamarin 中 webview 的链接调用 whatsapp?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52394121/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com