How to open an URL in Android’s web browser

Here’s a code snippet to show you how to use “android.content.Intent” to open an specify URL in Android’s web browser.


	button.setOnClickListener(new OnClickListener() {

		@Override
		public void onClick(View arg0) {

			Intent intent = new Intent(Intent.ACTION_VIEW, 
			     Uri.parse("https://mkyong.com"));
			startActivity(intent);

		}

	});
Note
For full example, please refer to this – Android button example.

References

  1. Android Button JavaDoc
  2. Android Intent.ACTION_VIEW JavaDoc

mkyong

Founder of Mkyong.com, passionate Java and open-source technologies. If you enjoy my tutorials, consider making a donation to these charities.

8 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
SriRam
10 years ago

i want to call a url – nothing to be displayed or nothing to be get as a rsponce but i want to call that – can you help me with any snippet

fatima
11 years ago

it was a great help thankyou !

Aman
10 years ago

this will open the browser, but how to open the link in background

Aman
10 years ago
Reply to  Aman

i mean the link whatever i put there it open it in foreground, but i want to do same but in background. is it possible to execute the given link in background????

Tharindu Irashana
10 years ago

thank you sir

avon
12 years ago

thank you !!!!

haris
13 years ago

How to create a browser with block of all unwanted url’s in android??

Gowtham Raj
13 years ago

easy to understand