Cordova Share via WhatsApp from a click inside WebView

这一生的挚爱 提交于 2020-01-02 04:34:15

问题


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:

Any idea how to solve this ?


回答1:


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.



来源:https://stackoverflow.com/questions/31863998/cordova-share-via-whatsapp-from-a-click-inside-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!