JavaFX Application Custom Scheme URI Handler

天涯浪子 提交于 2021-02-11 18:18:13

问题


I have created a JavaFX Application which can be open using a custom scheme myscheme://argument1/argument2

I have successfully implemented the info.plist file which has the following content:

<key>CFBundleURLTypes</key>


<array>
   <dict>
       <key>CFBundleURLName</key>
       <string>com.myapp.Main</string>
       <key>CFBundleURLSchemes</key>
       <array>
          <string>myscheme</string> // <-- this is the scheme which can open the application
       </array>
   </dict>
</array>

Now after this i'm successfully able to open my application using archor tag in the html page

<a href="scheme://argument1">Open App</a>

The problem I'm facing is related to the argument, My question is very simple how can I receive arguments in a callback within my application. Right now my main class looks like this:

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Parent root = FXMLLoader.load(getClass().getResource("layouts/main.fxml"));
        primaryStage.setTitle(title);
        primaryStage.setScene(new Scene(root, screenSize.getWidth() / 2, screenSize.getHeight() / 2));
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

I have also tried googling it but couldn't find my answer any help will be appreciated

来源:https://stackoverflow.com/questions/60182607/javafx-application-custom-scheme-uri-handler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!