Tuesday 10 December 2013

How to open a website in android.


 In This tutorial I am going to display how you can open a website in android by using intent. This is a simplest way to open a website. you just have to put the code on a button or any other widget and implement a on click listener on it and the rest of the work will be done in the browser.

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity{

    Button visit;
   
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
        visit=(Button)findViewById(R.id.visit);
       
        visit.setOnClickListener(new OnClickListener() {
           
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Uri uri=Uri.parse("http://itdevelopersdelhi.in/");
                Intent k=new Intent(Intent.ACTION_VIEW,uri);
                startActivity(k);
            }
        });
       
    }
}




Snapshots:- 


Download The Project:-


No comments:

Post a Comment