A simple java library that calls system commands to open and register applications with an URIScheme. See http://en.wikipedia.org/wiki/URI_scheme
Browsers use the URI Schemes handlers registered with the OS to decide which application to use to handle a URI scheme.
For example the mailto scheme name is usually associated with your default email client, so if there is something like this on
a website:
mailto:foo@bar.com
It will open your email client when you click on it.
To use just add to your pom
<dependency>
<groupId>com.github.beothorn</groupId>
<artifactId>URISchemeHandler</artifactId>
<version>2.0.0</version>
</dependency>
Opening an URIScheme string with default handler:
String magnetLink = "magnet:?xt=urn:foobarbaz";
URI magnetLinkUri = new URI(magnetLink);
URISchemeHandler uriSchemeHandler = new URISchemeHandler();
uriSchemeHandler.open(magnetLinkUri);
This will open the torrent client registered with the os to handle the magnet scheme name. For example, if you install utorrent, utorrent will open and ask you if you want to add the magnet link to your downloads.
Registering a URIScheme
URISchemeHandler urlHandler = new URISchemeHandler();
String schemeName = "mySchemeHandler";
urlHandler.register(schemeName,"c:\\mySchemeHandler.exe"); //c:\\mySchemeHandler.exe or any command to receive the URI as parameter
Before adding a new scheme, make sure it doesn't conflict with an existing one. There's a list of them on the wikipedia article mentioned above.
- No need for admin user for windows
- Added support for mac
Thanks @lionel1704 @dmmop