Taranasus
Taranasus

Reputation: 535

How to open the default android browser without specifying an URL?

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?

Upvotes: 4

Views: 2848

Answers (2)

Richard Rout
Richard Rout

Reputation: 1316

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.

Upvotes: 3

DonGru
DonGru

Reputation: 13710

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

startActivity( new Intent( Intent.ACTION_VIEW, Uri.parse("about:blank")));

Upvotes: 4

Related Questions