Running URI Commands in Java

One of the ways that Steam allows users to launch games and perform many other operations is, for example, using the URI protocols (from the Valve developer community )

steam://run/<id> will launch the game corresponding to the specified ID.

steam://validate/<id> will check the game files for the specified identifier.

How can I get Java to run these? I don’t even know what you call it, i.e. Do you run URIs or execute them or what? Since these URIs apparently have nothing to return, and the Java URI class has nothing to do with its execution, however the URL does, but it doesn't work!

I tried this:

 ... try { URI testURI = URI.create("steam://run/240"); URL testURL = joinURI.toURL(); // URL testURL = new URL("steam://run/240") doesn't work either joinURL.openConnection(); // Doesn't work // joinURL.openStream() doesn't work either } catch (MalformedURLException e) { System.err.println(e.getMessage()); } ... 

Each combination gives an error: unknown protocol: steam .

The system Steam uses to process URIs definitely works because, for example, I can enter the above URIs in Firefox and work.

My eternal gratitude to the person who gives the answer!

thanks

+4
source share
3 answers

Try Desktop.browse(URI) , this should trigger a "default action", which is the Steam client for steam:// URI, for example

 URI uri = new URI("steam://store/240"); if (Desktop.isDesktopSupported()) { Desktop.getDesktop().browse(uri); } 
+7
source

The system Steam uses to process URIs definitely works because, for example, I can enter the above URIs in Firefox and work.

It works because Firefox (or other browsers) can associate implicit protocols with applications. When you download steam://xxx for the first time, Firefox asks which application you want to open. If he did not ask you, perhaps a browser plug-in was installed for this.

0
source

A Uniform Resource Identifier (URI) simply identifies a resource; it does not necessarily describe how to access it. Moreover, for user protocols such as β€œsteam,” the provider can define any basic access agreements that compatible client programs must know to communicate.

To "execute" a URI like this, you need to know exactly how the protocol is implemented (is it through HTTP? TCP? UDP?) And how to talk to the server on the other end.

Valve's developer community wiki page may have helpful information.

0
source

All Articles