user3109249
user3109249

Reputation:

Start whatsapp from webview

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

Upvotes: 3

Views: 10484

Answers (6)

Ucdemir
Ucdemir

Reputation: 3098

 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;
        }
    });

Upvotes: 4

HoldOffHunger
HoldOffHunger

Reputation: 20931

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

Upvotes: 1

Nagibaba
Nagibaba

Reputation: 5368

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;
            }
        }
    });

Upvotes: 0

Juan G Carmona
Juan G Carmona

Reputation: 2208

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)

Upvotes: 0

Farib Khojaste
Farib Khojaste

Reputation: 85

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

Upvotes: 0

Opos
Opos

Reputation: 36

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

Upvotes: 1

Related Questions