I have made a web-view of a website. Now I want to share some data from my web-view to whatsapp app. I was able to open whatsapp web, but my client wants me to open whatsapp application instead of whatsapp web. How can I do that?
This is what I have done to open whatsapp web in my site:
<a class="social-icon whatsapp"
href="javascript:popWin('https://api.whatsapp.com/send?text=Product%20Name:-<?php echo $productName; ?>.%20Product%20link:-<?php echo $productUrl; ?>', 'whatsapp', 'width=640, height=480, left=0, top=0, location=no, status=yes, scrollbars=yes, resizable=yes');"
title="<?php echo $this->__('Share on Whatsapp') ?>"
data-action="share/whatsapp/share">
<span><i class="fa fa-whatsapp"></i></span>
</a>
@Override
public boolean shouldOverrideUrlLoading(WebView wv, String url) {
if(url.startsWith("tel:") || url.startsWith("whatsapp:")) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
return true;
}
return false;
}
Put this code in your mWebView.setWebViewClient(new WebViewClient(). it will be working perfectly for all link like tel:, whatsapp: etc.
Use this and works ok. (@NSMedia-Solution) Just put
'myWebView.goBack();'
before return (For not navigate in whatsApp web)
myWebView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView wv, String url) {
if(url.startsWith("tel:") || url.startsWith("whatsapp:")) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
myWebView.goBack();
return true;
}
return false;
}
});
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView wv, String url) {
if(url.startsWith("tel:") || url.startsWith("whatsapp:") || url.startsWith("intent://") || url.startsWith("http://") ) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
webView.goBack();
return true;
}
return false;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
invalidateOptionsMenu();
}
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
try {
invalidateOptionsMenu();
} catch (Exception e) {
}
if (webView.canGoBack()) {
webView.goBack();
}
}
public void onPageFinished(WebView view, String url) {
// pullToRefresh.setRefreshing(false);
invalidateOptionsMenu();
}
});
my problem solves using this code.
You can use, its working for me:
Option First-
<a href="whatsapp://send?text=Hello friend!" data-action="share/whatsapp/share">Share</a>
Option Second-
<a href="https://api.whatsapp.com/send?text=Hello friend!" data-action="share/whatsapp/share">Share</a>
Both options are working for me..
If not working to your side then please update android version of your mobile phone & also update whatsapp version
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With