Loading
Structure of this intent url is described here https://developer.chrome.com/multidevice/android/intents.
So we can handle it in internal WebView like this:
First we have to create class that extends to WebViewClient
private class CustomWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView wv, String url) {if (url.startsWith("tel:")) {
Intent intent1 = new Intent(Intent.ACTION_VIEW);
intent1.setData(Uri.parse(url));
startActivity(intent1);
return true;
} else if (url.startsWith("sms:")) {
Intent intent1 = new Intent(Intent.ACTION_VIEW);
intent1.setData(Uri.parse(url));
startActivity(intent1);
return true;
} else if (url.startsWith("https://www.google.com/maps/")) {
Intent intent1 = new Intent(Intent.ACTION_VIEW);
intent1.setData(Uri.parse(url));
startActivity(intent1);
return true;
} else if (url.startsWith("whatsapp:")) {
Intent intent1 = new Intent(Intent.ACTION_VIEW);
intent1.setData(Uri.parse(url));
startActivity(intent1);
return true;
} else if (url.startsWith("https://play.")) {
Intent intent1 = new Intent(Intent.ACTION_VIEW);
intent1.setData(Uri.parse(url));
startActivity(intent1);
return true;
} else if (url.startsWith("https://www.youtube.com")) {
Intent intent1 = new Intent(Intent.ACTION_VIEW);
intent1.setData(Uri.parse(url));
startActivity(intent1);
return true;
} else if (url.startsWith("https://www.linkedin.com")) {
Intent intent1 = new Intent(Intent.ACTION_VIEW);
intent1.setData(Uri.parse(url));
startActivity(intent1);
return true;
} else if (url.startsWith("mailto:")) {
Intent intent1 = new Intent(Intent.ACTION_VIEW);
intent1.setData(Uri.parse(url));
startActivity(intent1);
return true;
} else if (url.startsWith("https://www.facebook.com")) {
Intent intent1 = new Intent(Intent.ACTION_VIEW);
intent1.setData(Uri.parse(url));
startActivity(intent1);
return true;
} else if (url.startsWith("https://www.m.facebook.com")) {
Intent intent1 = new Intent(Intent.ACTION_VIEW);
intent1.setData(Uri.parse(url));
startActivity(intent1);
return true;
} else if (url.startsWith("https://twitter.com")) {
Intent intent1 = new Intent(Intent.ACTION_VIEW);
intent1.setData(Uri.parse(url));
startActivity(intent1);
return true;
} else {
webUrl = wv1.getUrl();
}
return false;
}
}
After Creating function we call this function from oncreate method
private WebView wv1;
private String url="https://google.com";@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wv1 = findViewById(R.id.webView);
wv1.setWebViewClient(new CustomWebViewClient());
wv1.loadUrl(url);
}
Thats it via this code we can redirect links like call, sms, mail, map, whatsapp, playstore, youtube, etc.
Comments (0)
Leave A Comment
Your email address will not be published. Required fields are marked *