6

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 ?

vbotio
  • 1,566
  • 3
  • 26
  • 53
  • It's not clear to me. First you open your website on inAppBrowser and the web you open has whatsapp links? – jcesarmobile Aug 07 '15 at 06:48
  • @jcesarmobile exactly – vbotio Aug 07 '15 at 14:34
  • @jcesarmobile same error appearing on my side as well. I have opened my website using inappbrowser for android. it has addtoany social media sharing icons and whatsapp is showing this error – Heemanshu Bhalla May 21 '18 at 22:14
  • @HeemanshuBhalla, so you are using InAppBrowser, so what I said for the other question doesn't apply, that's for inside the Cordova webview. As I said, better create your own question and provide more information, such as that you are using InAppBrowser and that happens when the website has social media buttons, and an example of what those buttons do might be helpful too – jcesarmobile May 22 '18 at 09:05
  • Ok sure @jcesarmobile. I will do soon. – Heemanshu Bhalla May 23 '18 at 09:34
  • Possible duplicate of [Ionic InAppBrowser on Android doesn't navigate to custom Url Scheme](https://stackoverflow.com/questions/51908666/ionic-inappbrowser-on-android-doesnt-navigate-to-custom-url-scheme) – Saurin Dashadia Jan 31 '19 at 11:59
  • Whose looking for answer please check this https://stackoverflow.com/a/53502532/3260012 – Saurin Dashadia Jan 31 '19 at 12:00

1 Answers1

6

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.

vbotio
  • 1,566
  • 3
  • 26
  • 53
  • 2
    +vbotio I think you should mark your answer as the accepted one (the green V shaped icon). This is the same solution I've found to the same problem that was happening with an Android App trying to open Whatsapp from within a WebView. – Ulysses Alves Oct 29 '15 at 13:46
  • 4
    This solution not working for me even after editing the ' InAppBrowser.java' file. – Ravimallya Feb 05 '17 at 08:28
  • 1
    It didn't helped me as well i have applied both changes mentioned – Heemanshu Bhalla Feb 17 '18 at 03:07
  • It didnt work for me too.... Any solution? I am trying to load whatsapp custom schema "whatsapp://" from in-app-browser. Where the link is on loaded page. – Saurin Dashadia Jan 31 '19 at 11:51
  • @SD can you provide more details about your problem ? – vbotio Feb 03 '19 at 22:56
  • Sure. It was same as question. The webpage, that is being called in ionic webview has WhatsApp message send link. It works fine on mobile browser. But didn't work on ionic webview. It was solved using custom scheme. – Saurin Dashadia Feb 04 '19 at 05:49
  • This solution worked perfectly in my case, actually @vbotio you should create a pull request onto the inappbrowser git project IMHO. Thanks for your help btw! – nnimis Jun 21 '20 at 00:38
  • @nnimis can you please add your code from the Ionic / Cordova side ? how your opening the custom URL schema ? – Vasanth Jun 22 '20 at 07:27
  • @Vasanth I haven't yet implemented it on the Cordova side, it needs to be implemented on Android code (by changing app/java/org.apache.cordova/InAppBrowser.java as described on the solution) – nnimis Jun 22 '20 at 08:14
  • Yeah, I'm aware of that, you need to trigger that from Cordova /Ionic right ? Ex: cordova.InAppBrowser.open(url, target, options); I wanted to know that piece of code – Vasanth Jun 22 '20 at 08:17