是否可以从URL启动应用程序并从应用程序内部处理URL内容? [英] Is it possible to launch app from URL and handle the URL content from inside app?

查看:130
本文介绍了是否可以从URL启动应用程序并从应用程序内部处理URL内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用一种功能,用户可以从中按下项目文件来启动我的应用程序/应用程序.我的目光是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.pliston 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:

在Gluon Charm库中:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆