3

I have an app that loads a newspaper site in a webview. In that site you can share a news in facebook, twitter and whatsapp. I have facebook's and twitter's links covered with

shouldOverrideUrlLoading()

I can't figer out how to launch the whatsapp app. It uses a custom URL scheme:

whatsapp://send?text=

I get: the webpage at whatsapp://send?text= could not be loaded because:

net::ERR_UNKNOWN_URL_SCHEME
Tim
  • 1,659
  • 1
  • 21
  • 33
  • This may help you: [Cordova Share via WhatsApp from a click inside WebView](http://stackoverflow.com/a/31880492/3110234) – activesince93 Nov 10 '15 at 12:56

6 Answers6

4
 webView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if(url.startsWith("tel:") || url.contains("https://wa.me/")) {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(url));
                startActivity(intent);
                return true;
            }
            return false;
        }
    });
Ucdemir
  • 2,852
  • 2
  • 26
  • 44
1

I suggest using loop from this question: using Intent.ACTION would give You best results.

Community
  • 1
  • 1
Opos
  • 36
  • 3
1

Don't use wa.me as a domain for sharing texts on whatsapp. Just test this URL here yourself: http://wa.me/?text=mytest. I see:

ERROR

PAGE NOT FOUND

Don't use the wa.me domain. Use the api.whatsapp.com domain. wa.me requires that you use a phone number. Well, typically, you want the share URL to be shared to other people that the user knows, so, you'd want to leave that blank. Check it out...

https://api.whatsapp.com/send?text=YourShareTextHere

https://api.whatsapp.com/send?text=YourShareTextHere&phone=123

Works for me! Hope this helps someone out there!

If you are interested in watching a project that keeps track of these URLs, then check us out!: https://github.com/bradvin/social-share-urls#whatsapp

Social Share URLs

Community
  • 1
  • 1
HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
0

be sure to have a proper URL encoded string after text=

Niki van Stein
  • 10,564
  • 3
  • 29
  • 62
0

I've just found that it is possible to open a conversation to a number Using Click to Chat

To create your own link with a pre-filled message that will automatically appear in the text field of a chat, use https://wa.me/whatsappphonenumber/?text=urlencodedtext where whatsappphonenumber is a full phone number in international format and URL-encodedtext is the URL-encoded pre-filled message.

Example:https://wa.me/15551234567?text=I'm%20interested%20in%20your%20car%20for%20sale

NOTE: It opens WhastApp application if you click the link using a mobile phone browser (at least from Android)

Juan
  • 2,156
  • 18
  • 26
0
this.webView.setWebViewClient(new WebViewClient(){
        @Override
        public boolean  shouldOverrideUrlLoading(WebView view, String url) {
            if (url != null && url.startsWith("https://wa.me")) {
                view.getContext().startActivity(
                        new Intent(Intent.ACTION_VIEW, Uri.parse(url.replace("+",""))));

                return true;

            } else {
                return false;
            }
        }
    });
Nagibaba
  • 4,218
  • 1
  • 35
  • 43