Handle custom URL schemes in an OS X Java application

后端 未结 3 1111
我在风中等你
我在风中等你 2020-12-16 07:21

The Info.plist of our Java-based application contains following entries:




        
3条回答
  •  醉梦人生
    2020-12-16 07:57

    With Java 9, this is easy quite easy, and no longer requires Apple's EAWT classes or any ObjC hackery.

        Desktop.getDesktop().setOpenURIHandler((event) -> {
            System.out.println("Open URI: " + event.getURI());
            // do something with the URI
        });
    

    The application needs to be bundled, and the CFBundleURLTypes key must be set.

    
    CFBundleURLTypes
    
      
        CFBundleURLSchemes
        
            example
        
        CFBundleURLName
        
      
    
    

    Unfortunately this only captures the URI if the application is already running. If the application was launched by opening a URI, the event is not delivered (see comments on ed22's answer).

提交回复
热议问题