open a url on click of ok button in android


Question

I have to open a URL on Click of OK Button in a view. Can someone tell how to do this?

1
85
3/24/2014 4:41:40 PM

Accepted Answer

On Button click event write this:

Uri uri = Uri.parse("http://www.google.com"); // missing 'http://' will cause crashed
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

that open the your URL.

218
7/20/2015 10:08:33 AM

    Button imageLogo = (Button)findViewById(R.id.iv_logo);
    imageLogo.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            String url = "http://www.gobloggerslive.com";

            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            startActivity(i);
        }
    });

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon