4

I'm loosing my mind over this. I want to open the user's default web browser. I can use this:

startActivity( new Intent( Intent.ACTION_VIEW, Uri.parse("http://google.com")));

To open the browser and send the user to that URL. But I don't want to send him to a specific URL, I just want to open the browser. I'm sure it's a simple solution, I just can't find it. Any Ideas?

Taranasus
  • 515
  • 5
  • 12

2 Answers2

4

To just open the browser without any URL opened you can use

startActivity( new Intent( Intent.ACTION_VIEW, Uri.parse("about:blank")));
DonGru
  • 13,532
  • 8
  • 45
  • 55
  • Yeah that's good but the problem with that is that... for example in a browser like Dolphin it opens a blank page. I would like it to open the default SpeedDial page – Taranasus Sep 15 '11 at 08:30
  • ah okay, I see the point - you should probably add that to your question, that makes things clearer – DonGru Sep 15 '11 at 10:26
3

After a bunch of searching, I was able to do this:

PackageManager pm = getPackageManager();
Intent queryIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
ActivityInfo af = queryIntent.resolveActivityInfo(pm, 0);
Intent launchIntent = new Intent(Intent.ACTION_MAIN);
launchIntent.setClassName(af.packageName, af.name);
startActivity(launchIntent);

It basically says "What application would handle this?". Then it grabs that applications package and class name then fires an intent for the main action.

Richard Rout
  • 1,296
  • 1
  • 15
  • 28