Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova Share via WhatsApp from a click inside WebView

I've my app built with Cordova (5.5.1) and I'm trying to share Url's via WhatsApp. I'm using the following protocol: whatsapp://send?text= test

If I open my website on a mobile browser it's working. On iOS it's working as well.

I've tried to add this <access origin="whatsapp:*" launch-external="yes" /> to my config.xml but it still not working.

I'm using InAppBrowser and this is how I'm opening 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 idea how to solve this ?

like image 787
vbotio Avatar asked Aug 06 '15 19:08

vbotio


1 Answers

I solved it editing the core of 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 <access origin="whatsapp:*" launch-external="yes" /> in your config.xml as well.

like image 198
vbotio Avatar answered Sep 22 '22 05:09

vbotio