Cordova Share via WhatsApp from a click inside WebView

I have an app built in Cordova (5.5.1) and I am trying to share a URL via WhatsApp. I am using the following protocol:whatsapp://send?text= test

If I open my site in a mobile browser, it works. This works on iOS as well.

I tried to add this one <access origin="whatsapp:*" launch-external="yes"/>

to my config.xml but it still doesn't work.

I am using InAppBrowser and this is how I open my webview

var ref = window.open("http://m.estadao.com.br/?load-all=true", "_blank", "location=no", "toolbar=no", "closebuttoncaption=a", "EnableViewPortScale=no");

Here is the error: error cordova whatsapp

Any ideas how to solve this?

+5


source to share


2 answers


I decided to edit it core plugin InAppBrowser.java

Changed this

else if (url.startsWith("geo:") || url.startsWith(WebView.SCHEME_MAILTO) || url.startsWith("market:")){
            try {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(url));
                cordova.getActivity().startActivity(intent);
            } catch (android.content.ActivityNotFoundException e) {
                LOG.e(LOG_TAG, "Error with " + url + ": " + e.toString());
            }
        }

      



to

else if (url.startsWith("geo:") || url.startsWith(WebView.SCHEME_MAILTO) || url.startsWith("market:") || url.startsWith("whatsapp:"))  {
            try {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(url));
                cordova.getActivity().startActivity(intent);
            } catch (android.content.ActivityNotFoundException e) {
                LOG.e(LOG_TAG, "Error with " + url + ": " + e.toString());
            }
        }

      

It's important to add this one <access origin="whatsapp:*" launch-external="yes" />

to your config.xml file.

+4


source


 refInAppBrowser.addEventListener('loadstop', (e) => {
       if(e.url.startsWith("whatsapp:")){
            window.location.href=e.url;
        }
 });

      



0


source







All Articles