How to make Android’s WebView opens a link inside or outside current app?

Initially if we use a WebView in our Android app, if there is a link and we click it, an intent manager is being called and asking how do we want to open that link. But we can manage it to open that link inside current that WebView or regular web browser.

To do so, we need to examine what kind of link is it. In this example, I tell the WebView that if the link contains some word, for example “zofiakreasi” then please open it directly, and if not then run an intent manager so users can choose how to open that link.

browser.setWebViewClient(new WebViewClient() {
	public boolean shouldOverrideUrlLoading(WebView viewx, String urlx) {
			return false;
			Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlx));
			return true;
	public void onReceivedError(WebView webview, int i, String s, String s1){

If you have more word to examine, you can do “else if” statement or using “or” operator inside your “if” statement.


Leave a Reply

Your email address will not be published.