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
  • Learn more about WebViewClient. Commented Nov 21, 2012 at 11:35
  • How can I open a URL in Android's web browser from my application? stackoverflow.com/q/2201917/1012284 Commented Nov 21, 2012 at 11:37
  • add INTERNET permission in manifest file Commented Nov 21, 2012 at 11:42

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

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

1 Comment

Your answer would be considerably better if you could explain why you think this answers the question.
0

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.