open a url on click of ok button in android

前端 未结 6 394
情深已故
情深已故 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:42

    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 have to check that the URL is valid or not. If URL is invalid application may crash so that you have to check URL is valid or not by this method.

提交回复
热议问题