How can I open a URL in Android's web browser from my application?

前端 未结 30 2811
庸人自扰
庸人自扰 2020-11-21 22:09

How to open an URL from code in the built-in web browser rather than within my application?

I tried this:

try {
    Intent myIntent = new Intent(Int         


        
30条回答
  •  我寻月下人不归
    2020-11-21 22:44

    String url = "https://www.thandroid-mania.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();
    }
    

    That error occurred because of invalid URL, Android OS can't find action view for your data. So you have validate that the URL is valid or not.

提交回复
热议问题