是否可以从URL启动应用程序并从应用程序内部处理URL内容? [英] Is it possible to launch app from URL and handle the URL content from inside app?
问题描述
我想使用一种功能,用户可以从中按下项目文件来启动我的应用程序/应用程序.我的目光是com.gluonhq.charm.down.plugins.RuntimeArgsService
Gluon服务.
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.
我的第一步是仅从URL启动应用程序.但是-我想知道是否/如何使我的应用程序从启动的URL中知道-因此它可以自动导入该项目并向用户显示.
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.
能否将启动URL提供给应用程序/应用程序-这样它就可以知道从何处启动?
推荐答案
通过对Android的AndroidManifest.xml
和iOS上的Default-Info.plist
进行修改,并使用com.gluonhq.charm.down.plugins.RuntimeArgsService
即可.
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);
});
});
(import static com.gluonhq.charm.down.plugins.RuntimeArgsService.LAUNCH_URL_KEY
是必需的)
con在这里(用于Consumer对象),包含启动应用程序所在的URL.以我为例,我创建了一个名为.example
的文件.这导致我修改了AndroidManifest.xml
文件,这也是需要的:
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:
向AndroidManifest.xml
文件添加了以下内容:
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).
以下是有关必要标签类型的Android文档.它指出必须强制提供某些文件(以便将文件扩展名与您的应用相关联-等等).我遇到了这篇文章无法打开自定义文件扩展名.请注意,他正在将方案设置为必要的文件".
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.
请记住,即使您未将某些data
设置为任何特定内容,也需要添加这些内容.这一切使我可以从指定的文件扩展名类型启动我的应用,然后通过对象con
通过侦听器接收url.
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
.
在iOS上,我通过在Defualt-Info.plist
文件内添加两个键来实现此目的.通过添加这些内容,我告诉系统我的应用程序可以打开".exa"(如示例)文件. "TryingService"是Gluon应用程序的名称.
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.
在iOS上也可以通过对Defualt-Info.plist
文件进行编辑来接收URL方案,如下所述:
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.
在Android上,也应该使用intents
-Gluon Charm Down库中的ShareService
已经使用过intents
: 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
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
这篇关于是否可以从URL启动应用程序并从应用程序内部处理URL内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!