open a url on click of ok button in android

前端 未结 6 393
情深已故
情深已故 2020-12-12 17:15

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

6条回答
  •  半阙折子戏
    2020-12-12 17:19

    create an intent and set an action for it while 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);
    

提交回复
热议问题