Send intent to browser to open specific URL [repeat]

This article was translated from: Sending an Intent to browser to open specific URL [duplicate]

This question already has an answer here: This question already has an answer here :

I'm just wondering how to fire up an Intent to the phone's browser to open an specific URL and display it. I just want to know how to start an Intent in the mobile browser to open a specific URL and display it.

Can someone please give me a hint? Can someone please give me a hint ?


#1st Floor

Reference: https://stackoom.com/question/Cbbv/ Send intent to browser to open a specific URL-repeat


#2nd Floor

In some cases URL may start with "www". In some cases, the URL may start with "www" . In this case you will get an exception: In this case, you will get an exception:

android.content.ActivityNotFoundException: No Activity found to handle Intent

The URL must always start with "http: //" or "https: //" so I use this snipped of code: The URL must always start with "http: //" or "https: //" , so I use The following code snippet:

if (!url.startsWith("https://") && !url.startsWith("http://")){
    url = "http://" + url;
}
Intent openUrlIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(openUrlIntent);

#3rd floor

The shortest version.

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")));

#4th floor

From XML through XML

In case if you have the web- address / URL displayed on your view and you want it to make it clikable and direct user to particular website You can use: If you see a Web address / URL, your views and hope that it will enable users To make it easier to understand and direct it to a specific website, you can use:

android:autoLink="web"

In the same way you can use different attributes of autoLink (email, phone, map, all) to accomplish your task ... Similarly, you can use different attributes of autoLink (email, phone, map, etc.) to complete the task ...


#5th Floor

Use following snippet in your code , use the following code snippet

Intent newIntent = new Intent(Intent.ACTION_VIEW, 
Uri.parse("https://www.google.co.in/?gws_rd=cr"));
startActivity(newIntent);

Use This link Use this link

http://developer.android.com/reference/android/content/Intent.html#ACTION_VIEW http://developer.android.com/reference/android/content/Intent.html#ACTION_VIEW


#6th floor

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);
Published 0 original articles · praised 8 · 30,000+ views

Guess you like

Origin blog.csdn.net/asdfgh0077/article/details/105469895