1

How can I open a url in the android web browser from my application on clicking a button.

I tried this :

Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(strURL));

startActivity(myIntent);

but I am getting exception:

but I got an Exception :

 "No activity found to handle Intent{action=android.intent.action.VIEW data =www.google.com"
3

4 Answers 4

2

You are doing it fundamentally correct, you just need to include the full url.

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

Basically, the http is the protocol. It is the computer's way of trying to figure out how you want to open it. You might also be interested in https, if you want a secure connection over SSL.

1

Almost seems like this would be useful to read... from the page:

Uri uri = Uri.parse("http://androidbook.blogspot.com");
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uri);
startActivity(launchBrowser);

There is a second way, involving the WebView, but that seems like it's not your question. Hope this helped.

0
String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
1
  • 1
    Your answer would be considerably better if you could explain why you think this answers the question.
    – Ben
    Nov 21, 2012 at 11:54
0

Follow this For More Detail

Try this:

String strURL = "http://www.google.com";
        Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(strURL));

        startActivity(myIntent);

As for the missing "http://" I'd just do something like this:

if (!url.startsWith("http://") && !url.startsWith("https://"))
   url = "http://" + url;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.