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

前端 未结 30 2775
庸人自扰
庸人自扰 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 23:08

    I think this is the best

    openBrowser(context, "http://www.google.com")
    

    Put below code into global class

        public static void openBrowser(Context context, String url) {
    
            if (!url.startsWith("http://") && !url.startsWith("https://"))
                url = "http://" + url;
    
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            context.startActivity(browserIntent);
        }
    

提交回复
热议问题