17

I programmattically open an Url in a browser by:

private final String url = "https://www.google.com";

Uri uri = Uri.parse(url);
Intent intent = new Intent();
intent.setData(uri);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);

Generally, the code works fine, it opens the Http address in a browser.

But there is always a system pop up dialog ask user to select an app to complete the action first:

enter image description here

User has to select Chrome from the pop up, after then, the page opens. I don't understand why the google+ app is among the options.

How could I avoid this system dialog for app selection ? I mean how can I set a default browser (Chrome) & my code could just open the url without this system dialog ?

user842225
  • 5,445
  • 15
  • 69
  • 119
  • This popup is not going away. Even when you have action.view the device may have more apps installed that can open a url for viewing such as default web browser, safari, etc. – danny117 Mar 30 '15 at 16:30

1 Answers1

33

Use

Intent intent= new Intent(Intent.ACTION_VIEW,Uri.parse(YOUR_URL));
startActivity(intent);

But you will still have to choose between different browsers or rather activities that support this action and data.

Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289