Rectangle 27 0

android Sending an Intent to browser to open specific URL?


Intent.ACTION_VIEW
String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
http
https
if (!url.startsWith("http://") && !url.startsWith("https://")) 	url = "http://" + url;

Encode the Query String If any special characters or spaces. then It will work awesome.For Example : String query="For martin Luther King"; query=URLEncoder.encode(query); String url="en.wikipedia.org/wiki/Special:Search?search="+query; Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(browserIntent);

From Android Developer web site: Caution: If there are no apps on the device that can receive the implicit intent, your app will crash when it calls startActivity(). To first verify that an app exists to receive the intent, call resolveActivity() on your Intent object. If the result is non-null, there is at least one app that can handle the intent and it's safe to call startActivity(). If the result is null, you should not use the intent and, if possible, you should disable the feature that invokes the intent.

Funny thing here is that startActivity(i) line could produce ActivityNotFound exception so I go for wrap this line in try/catch block to prevent app crash. This could happen if really no browser app installed on target device (yeah, shoot happens) also it could be that your app was forbidden to start a browser using restrict profiles.

Hi you solution is good but by this process , it search on google first then redirect to browser. I am using Nexus 4 and see this problem. I hope you will check it.

To open a URL/website you do the following:

Note
Rectangle 27 0

android Sending an Intent to browser to open specific URL?


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

android Sending an Intent to browser to open specific URL?


Matcher _SCHEMA_MATCHER = Pattern.compile("(https?://|mailto:).+").matcher("")
_SCHEMA_MATCHER.reset(uri).matches()? uri :  "http://" + uri
android.content.ActivityNotFoundException: No Activity found to handle Intent
if (!url.startsWith("https://") && !url.startsWith("http://")){
    url = "http://" + url;
}
Intent openUrlIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(openUrlIntent);

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

Note
Rectangle 27 0

android Sending an Intent to browser to open specific URL?


Intent i = new Intent(Intent.ACTION_VIEW, 
       Uri.parse("http://almondmendoza.com/android-applications/"));
startActivity(i);

should work as well...

Note
Rectangle 27 0

android Sending an Intent to browser to open specific URL?


I guess if you used an intent to launch the Maps App with the coords, that would work also.

I have found that if I pass a URL containing the coords to the browser, Android asks if I want the browser or the Maps app, as long as the user hasn't chosen the browser as the default. See my answer here for more info on the formating of the URL.

Note
Rectangle 27 0

android Sending an Intent to browser to open specific URL?


Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.stackoverflow.com")); 
startActivity(intent);
String url = "http://www.stackoverflow.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url)); 
startActivity(i);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.stackoverflow.com")));

I am sorry, but, I have to ask; Why did you edit this yesterday, 25 March 2015 when you actually posted the initial answer in 2013? And you only changed the word 'or' to 'or even more short!'. I don't get it :) Anyway, thank you for the info. :)))

What if the uri is missing http?

Note
Rectangle 27 0

android Sending an Intent to browser to open specific URL?


Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("geo:" + latitude + "," + longitude));
startActivity(intent);

You can use the geo URI prefix:

Note
Rectangle 27 0

android Sending an Intent to browser to open specific URL?


android:autoLink="web"

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:

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

Note
Rectangle 27 0

android Sending an Intent to browser to open specific URL?


Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);
Note
Rectangle 27 0

android Sending an Intent to browser to open specific URL?


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

Use following snippet in your code

Note