Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open url with an browser [duplicate]

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 ?

like image 218
user842225 Avatar asked Mar 30 '15 16:03

user842225


People also ask

How do I open a duplicate browser?

Open your preferred Internet browser. Access the web page you want to duplicate to a second browser tab. Right-click the browser tab and select Duplicate or Duplicate Tab, depending on the browser. You should see a second, duplicate tab opens with the same web page displayed as on the first tab.

How do I copy a URL from all open tabs in my browser?

Press Ctrl+C on Windows and Linux or Command+C on Mac to copy all your bookmarks. You can also right-click the list of selected bookmarks and choose “Copy.” Now, open the program where you want to paste all your open tab URLs (such as Notepad or TextEdit).

How do you copy a URL with multiple tabs?

Press Ctrl + a on Windows/Linux or ⌘ + a on Mac to select all bookmarks. Press Ctrl + c on Windows/Linux or ⌘ + c on Mac to copy all urls (and only urls).


1 Answers

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.

like image 54
Aniket Thakur Avatar answered Oct 16 '22 17:10

Aniket Thakur