String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
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: