0

In my Xamarin app there is have on a function to call web versions of e-commerce.

after the user views product details in the catalog and decides to place an order, they have to click on "Order Now" button and it will trigger Whatsapp message to the seller.

But after click it will popup error for cleartext permissions:

cleartext permissions

Then I add all the related Whatsapp URL in network_security_config as below:

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

After that its come out this error:

could not be load

What can I do to have webview for this e-commerce function and place an order will direct to Whatsapp message to send to the seller?

Ifwat Ibrahim
  • 1,523
  • 4
  • 16
  • 28
  • It sounds like this problem: https://stackoverflow.com/questions/41693263/android-webview-err-unknown-url-scheme Please also check this one: https://androidride.com/android-webview-example-tutorial-kotlin-java-download-source-code/#ERR_UNKNOWN_URL_SCHEME%20in%20Android%20WebView – Mihail Duchev May 04 '20 at 09:39

1 Answers1

0

I got the solution. Just stay to using webview function but have handling to filter which URL we want to.

In my case, I want to handle Whatsapp URL to navigate outside of the app. So I using this code:

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;
                }
            };
        }
Ifwat Ibrahim
  • 1,523
  • 4
  • 16
  • 28