Open url of ok button in android

I need to open the url on the OK button in the view. Can someone tell how to do this?

+87
android button click
Feb 08 '11 at 6:30
source share
5 answers

In Button click an event:

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

which will open your URL.

+220
Feb 08 '11 at 6:44
source share
  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); } }); 
+4
Jun 01 '17 at 12:36 on
source share

You can use the method below that will display your destination URL as a single input (don't forget http: //)

 void GoToURL(String url){ Uri uri = Uri.parse(url); Intent intent= new Intent(Intent.ACTION_VIEW,uri); startActivity(intent); } 
+1
Jun 26 '17 at 20:04 on
source share
 String url = "https://www.murait.com/"; if (url.startsWith("https://") || url.startsWith("http://")) { Uri uri = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); }else{ Toast.makeText(mContext, "Invalid Url", Toast.LENGTH_SHORT).show(); } 

You need to make sure the URL is valid or not. If the URL is invalid, the application may crash, so you should check if the URL is valid or not in this way.

+1
Aug 22 '19 at 2:34
source share

create an intent and set an action for it when passing the url to the intent

 yourbtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String theurl = "http://google.com"; Uri urlstr = Uri.parse(theurl); Intent urlintent = new Intent(); urlintent.setData(urlstr); urlintent.setAction(Intent.ACTION_VIEW); startActivity(urlintent); 
0
Apr 04 '18 at 13:39 on
source share



All Articles