Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Respecting/reading the "Preferred Applications" settings in Gnome (Linux)

Tags:

java

gnome

How do I find out the user's "preferred web browser", if they're using Gnome desktop environment? (I want to open a webpage, I don't need to know which browser the user prefers.)

Some background: I'm trying to open a browser window (my homepage) with my Java app.

  1. if Java version is 1.6+, use Desktop.browse(url);
  2. otherwise, use BareBonesBrowserLaunch.openURL(url) - that means checking the environment and starting a browser with Runtime.getRuntime().exec()

Method 2 works on Windows just fine; and opens a browser on Linux. However, it's the first browser that it finds (in my case, looks for Firefox first). In Gnome desktop environment (e.g. Ubuntu Linux has that by default), you could set your "Preferred Applications" for e-mail, www browsing etc; I believe this information is accesible somewhere. How can I find out which is the user's preferred browser?

In other words: where does Gnome store the "Preferred Browser" setting?

like image 589
Piskvor left the building Avatar asked Feb 28 '23 16:02

Piskvor left the building


1 Answers

The most portable way to open a file or URL in Linux desktop is xdg-open.

http://portland.freedesktop.org/xdg-utils-1.0/xdg-open.html

like image 120
Danilo Piazzalunga Avatar answered Apr 27 '23 08:04

Danilo Piazzalunga