Opening a web browser from an Android application

June 25, 2012

In this article we will create an application which will open a user input website in a web browser. In order to open a web browser, we will create an intent object with ACTION_VIEW as action and data with “http” in the url. Since http request is invoked by the external browser, no explicit permission is needed for this application.

1. Create a new Android project

New Android Project

Figure 1: New Android Project

2. Select build target for this application

Select build target

Figure 2: Select build target

3. Enter application details


Enter application details

Figure 3:Enter application details

4. res/values/strings.xml

<?xml version="1.0" encoding="utf-8"?>
    <string name="hello">Hello World, MainActivity!</string>
    <string name="app_name">BrowserDemo</string>
    <string name="hnt_te_url">Enter a website here ...</string>
    <string name="lbl_btn_browse">Browse</string>

5. res/layout/main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:orientation="vertical" >





6. src/in/wptrafficanalyzer/browserdemo/

package in.wptrafficanalyzer.browserdemo;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

        /** Getting a reference to the button object of the main.xml */
        Button btn = (Button) findViewById(;

        OnClickListener listener = new OnClickListener() {

            public void onClick(View v) {
                /** Getting a reference to the textedit object of the main.xml */
                EditText txt = (EditText) findViewById(;

                /** Creating a view action to display the website */
                Intent intent = new Intent("android.intent.action.VIEW");

                /** Setting up a uri object with a web address  */
                Uri data = Uri.parse("http://"+txt.getText().toString());

                /** Setting web address to the intent object as data */

                /** Start an activity that matches intent action and intent data */



7. Application  in execution


Main Activity

Figure 4: Main Activity

  •  Enter web address and click Browse button of the Main Activity
  • Then the entered website will be opened in a web browser.
  • If there are more than one web browser is available in the device, then system will prompt which browser should be used to open the site
Browser Activity

Figure 5: Browser Activity

8. Download

9. Reference

How to hire me?

I am George Mathew, working as software architect and Android app developer at

You can hire me on hourly basis or on project basis for Android applications development.

For hiring me, please mail your requirements to

My other blogs

Android Knowledge Quiz

Ready to test your knowledge in Android? Take this quiz :

Tags: , , , ,

One Response to Opening a web browser from an Android application

  1. kazi Ejaj on December 27, 2013 at 11:26 pm

    Thanks !!!! Bro

Leave a Reply

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

Be friend at g+

Subscribe for Lastest Updates

FBFPowered by ®Google Feedburner