10

Possible Duplicate:
How can I open a URL in Android’s web browser from my application?

I've been trying to find out how to create an intent that will open the specified URL in a Specified browser. Browser may not always be the default one. But i am unable to do so.

Community
  • 1
  • 1
Harshit Dubey
  • 121
  • 1
  • 1
  • 6

3 Answers3

20

Use the Intent.ACTION_VIEW constant as Intent action and the url as data.

final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
activity.startActivity(intent);

Note the URL must be a full URL (starting with either http:// or https://) so check in your code that the URL is not a short form such as www.google.com if it is user-defined.

Vincent Mimoun-Prat
  • 26,900
  • 13
  • 74
  • 118
2

try this :

String url = "your URL";
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
Houcine
  • 22,593
  • 13
  • 53
  • 83
0

You can use any of them, also read the Link

 Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://www.google.com")); 
startActivity(browserIntent); 

or

String url = "http://www.example.com";
 Intent i = new Intent(Intent.ACTION_VIEW); 
i.setData(Uri.parse(url)); startActivity(i); 
Stuti
  • 1,580
  • 1
  • 15
  • 32