簡體   English   中英

如何在 xamarin 中為 android 啟用或發送 whatsapp 消息

[英]How to enable or sent whatsapp message in xamarin for android

在我的 Xamarin 應用程序中有一個 function 調用 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>

之后它就出現了這個錯誤:

無法加載

我該怎么做才能讓這個電子商務 function 有 webview 並下訂單將直接發送到 Whatsapp 消息發送給賣家?

我得到了解決方案。 只需繼續使用 webview function 但要處理過濾我們想要的 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;
                }
            };
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM