【问题标题】:How to enable or sent whatsapp message in xamarin for android如何在 xamarin for android 中启用或发送 whatsapp 消息
【发布时间】:2020-05-04 03:39:16
【问题描述】:

在我的 Xamarin 应用程序中,有一个功能可以调用 Web 版本的电子商务。

用户查看目录中的产品详情并决定下单后,必须点击“立即下单”按钮,会触发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 消息发送给卖家?

【问题讨论】:

标签: c# android xaml xamarin webview


【解决方案1】:

我得到了解决方案。只需继续使用 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;
                }
            };
        }

【讨论】:

    猜你喜欢
    • 2021-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多