问题
I want to use a functionality from which the user can launch my app/application from pressing a project file. I have my eyes on the com.gluonhq.charm.down.plugins.RuntimeArgsService
Gluon service.
My first step will be to just launch the app from a URL. However - I would like to know if/how it could be possible to let my application know from what URL it was launched - so it can automatically import that project and display it for the user.
Can the launch URL be provided to the app/application - so it can know from where it was launched?
回答1:
With modification to the, AndroidManifest.xml
for Android - and Default-Info.plist
on iOS and by using the com.gluonhq.charm.down.plugins.RuntimeArgsService
this was possible.
Services.get(RuntimeArgsService.class).ifPresent(service -> {
service.addListener(LAUNCH_URL_KEY, con -> {
out("Received LAUNCH_URL_KEY: " + con);
});
});
(Theimport static com.gluonhq.charm.down.plugins.RuntimeArgsService.LAUNCH_URL_KEY
is required)
con here (for Consumer object), contains the url from where the app was launched from. In my case a file named .example
I made myself. And that lead me to the modification of the AndroidManifest.xml
file which was also needed:
To the AndroidManifest.xml
file I added the following:
In Gluon Charm library: http://docs.gluonhq.com/charm/javadoc/4.4.0/com/gluonhq/charm/down/plugins/RuntimeArgsService.html - it is explained how to use the service, but tells you to set you scheme as "yourScheme" (not taken literary ofcource).
Here is Android documentation about the type of tags neccassary. It states some are mandatory to give (in order to associate file extensions to your app - among other things). I came upon this post Cannot open custom file extension. Note that he is setting scheme to "file" which is neccassary.
Remember that some data
is required add even though you do not set them to anything specific. This all made it work for me to launch my app from the file extension type specified and then recieving the url through the listener by object con
.
On iOS I got this working by adding two keys inside the Defualt-Info.plist
file. By adding those I am telling the system that my app can open ".exa" (as in example) files. "TryingService" is the name of the Gluon application.
It is also possible on iOS to recieve url schemes with edits to the Defualt-Info.plist
file explained here: How can I open/send a URL to another app on iOS with a Gluon application? in the comments to that question.
And on Android it should also be possibel to use intents
- which is already used by the ShareService
in Gluon Charm Down library : https://bitbucket.org/gluon-oss/charm-down/src/153d43c06ff129f1ff93cc48a030c3a2cf099281/plugins/plugin-share/android/src/main/java/com/gluonhq/charm/down/plugins/android/AndroidShareService.java?at=default&fileviewer=file-view-default
来源:https://stackoverflow.com/questions/46820859/is-it-possible-to-launch-app-from-url-and-handle-the-url-content-from-inside-app