2013-04-11 3 views
0

버튼을 클릭 할 때 애플리케이션에서 URL을 열어 보겠습니다. 그래서 나는이 일을하고있다 :Mac OS에서 작동하지 않는 브라우저 링크 열기

Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; 
    System.out.println("Hey "+desktop); 
    if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { 
     try { 
      desktop.browse(new URL("http://support.apple.com/kb/DL1572").toURI()); 
      System.out.println("here"); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 

그러나 Desktop.isDesktopSupported() false를 반환합니다. 나는 Mac OS X 10.7.5를 사용하고있다. 어떤 대안?

+0

잘 작동합니다. OSX 10.7.5, 빌드 11G63b. – Perception

+0

흠 나는 내 컴퓨터에 없습니다. 그것의 신뢰할 수없는, 대안을 봐야 할 것이다. – Jatin

답변

0

Mac에서는이 작업을 수행합니다. this에게 감사 :

private void openUrlInBrowser(String url) 
{ 
Runtime runtime = Runtime.getRuntime(); 
String[] args = { "osascript", "-e", "open location \"" + url + "\"" }; 
try 
{ 
    Process process = runtime.exec(args); 
} 
catch (IOException e) 
{ 
// do what you want with this 
} 
}