如何在 xamarin 中为 android 启用或发送 whatsapp 消息
How to enable or sent whatsapp message in xamarin for android
在我的 Xamarin 应用程序中,有一个函数可以调用电子商务的 Web 版本。
用户查看目录中的产品详情并决定下订单后,他们必须单击 "Order Now" 按钮,这将触发向卖家发送 Whatsapp 消息。
但是点击后会弹出明文权限错误:
然后我在network_security_config中添加所有相关的Whatsapp URL如下:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">wa.me</domain>
<domain includeSubdomains="true">whatsapp.com</domain>
<domain includeSubdomains="true">whatsapp://send</domain>
</domain-config>
</network-security-config>
之后出现这个错误:
我该怎么做才能拥有此电子商务功能的 webview 并下订单将直接发送到 Whatsapp 消息以发送给卖家?
我得到了解决方案。继续使用 webview 函数,但可以处理过滤我们想要的 URL。
就我而言,我想处理 Whatsapp URL 以在应用程序外部导航。所以我使用这段代码:
void orderTapped(object sender, EventArgs e)
{
Device.OpenUri(new Uri("https://myecommercewebsite.com.my"));
}
protected override void OnAppearing()
{
base.OnAppearing();
wv.Source = "https://myecommercewebsite.com.my";
wv.Navigating += (s, e) =>
{
if (e.Url.StartsWith("whatsapp"))
{
try
{
var uri = new Uri(e.Url);
Device.OpenUri(uri);
}
catch (Exception)
{
}
e.Cancel = true;
}
};
}
在我的 Xamarin 应用程序中,有一个函数可以调用电子商务的 Web 版本。
用户查看目录中的产品详情并决定下订单后,他们必须单击 "Order Now" 按钮,这将触发向卖家发送 Whatsapp 消息。
但是点击后会弹出明文权限错误:
然后我在network_security_config中添加所有相关的Whatsapp URL如下:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">wa.me</domain>
<domain includeSubdomains="true">whatsapp.com</domain>
<domain includeSubdomains="true">whatsapp://send</domain>
</domain-config>
</network-security-config>
之后出现这个错误:
我该怎么做才能拥有此电子商务功能的 webview 并下订单将直接发送到 Whatsapp 消息以发送给卖家?
我得到了解决方案。继续使用 webview 函数,但可以处理过滤我们想要的 URL。
就我而言,我想处理 Whatsapp URL 以在应用程序外部导航。所以我使用这段代码:
void orderTapped(object sender, EventArgs e)
{
Device.OpenUri(new Uri("https://myecommercewebsite.com.my"));
}
protected override void OnAppearing()
{
base.OnAppearing();
wv.Source = "https://myecommercewebsite.com.my";
wv.Navigating += (s, e) =>
{
if (e.Url.StartsWith("whatsapp"))
{
try
{
var uri = new Uri(e.Url);
Device.OpenUri(uri);
}
catch (Exception)
{
}
e.Cancel = true;
}
};
}