Guest User

Untitled

a guest
Apr 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. public void launchURL(String url) {
  2. String osName = System.getProperty("os.name");
  3. try {
  4. if (osName.startsWith("Mac OS")) {
  5. Class fileMgr = Class.forName("com.apple.eio.FileManager");
  6. Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] {String.class});
  7. openURL.invoke(null, new Object[] {url});
  8. } else if (osName.startsWith("Windows"))
  9. Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
  10. else { //assume Unix or Linux
  11. String[] browsers = { "firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape", "safari" };
  12. String browser = null;
  13. for (int count = 0; count < browsers.length && browser == null; count++)
  14. if (Runtime.getRuntime().exec(new String[] {"which", browsers[count]}).waitFor() == 0)
  15. browser = browsers[count];
  16. if (browser == null) {
  17. throw new Exception("Could not find web browser");
  18. } else
  19. Runtime.getRuntime().exec(new String[] {browser, url});
  20. }
  21. } catch (Exception e) {
  22. pushMessage("Failed to open URL.", 0, "");
  23. }
  24. }
Add Comment
Please, Sign In to add comment