Open WhatsApp Url Link From Webview App to Default Browser

This Will be done by shouldOverrideUrlLoading Method in the below giving class.
Here is the Code 🙂 

public class myWebclientt extends WebViewClient {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}

@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {

if (url.contains("whatsapp")) {

try {
view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
// Stay within this webview and load url
/* view.loadUrl(url);
return true;*/
} catch (android.content.ActivityNotFoundException e) {
Toast.makeText(getApplicationContext(), "Application not installed",
Toast.LENGTH_LONG).show();
}
// Stay within this webview and load url
/* view.loadUrl(url);
return true;*/
}
return super.shouldOverrideUrlLoading(view, url);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *