Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

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

Posted on April 24, 2018August 4, 2020 by Habibie

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) {
		if(urlx.contains("zofiakreasi")){
			viewx.loadUrl(urlx);
			return false;
		}else{
			Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlx));
			startActivity(intent);
			return true;
		}
	}
	public void onReceivedError(WebView webview, int i, String s, String s1){
		webview.loadUrl("file:///android_asset/error.html");
	}
});

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

Post Views: 383
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Hover Reveal script for Unity to show and hide object on mouse hover
  • How to Prevent UI Clicks in Unity from “Bleeding Through” to 3D Objects Behind Them
  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Can’t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
© 2026 ThirteeNov | Powered by Superbs Personal Blog theme