Android的:在后台意图过滤器和网页 [英] Android: Intent-Filter and Web Page in Background

查看:153
本文介绍了Android的:在后台意图过滤器和网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我想检测我的Andr​​oid应用程序的网页(背景),使用过程中的意图过滤器,所以我的应用程序,我的网页分别做他们的工作。

I have a web page that I want to detect my Android App (in background) using intent-filter of course, so my App and my page do their work separately.

我的Andr​​oid应用程序处理类似下面使用意图过滤器的URL网址:

My android application handles a URL like the URL below using intent-filter:

myApp://sample?param=1

所以,我有一个< A> ,我点击它使用JavaScript代码在我的网页(自动):

So I have an <a> tag in my page which I clicked it using JavaScript (automatically):

<a href="myApp://sample?param=1" id="myAppLink"></a>

一切正常,exept我没有安装我的应用程序(例如,在PC或IOS)。
在这种情况下,浏览器重定向到对myApp://样本参数= 1 (自然)

Everything works fine exept when I don't have my App installed (for example in PC or iOS).
In this situation the browser redirects to myApp://sample?param=1 (naturally).

有什么办法(在JavaScript中,我认为),我可以检测,如果应用程序没有处理我的网址,然后我停止自动点击?或者其他的方式(当然招数)知道,如果安装了应用程序,然后我打电话单击事件?或者一些其他的解决办法,以我的问题?

Is there any way (in JavaScript I think) that I can detect if the app not handled my URL then I stop automatic clicking? Or other way (tricks of course) to know if the App installed then I call click event? Or some other workarounds to my problem?

或者,我可以叫我的网址(对myApp://样本参数= 1 )?使用AJAX和JSONP所以我的应用程序检测到它
(我一直没有机会尝试这种与jQuery阿贾克斯。我不知道,如果意向过滤器可以处理Ajax请求。)

Or can I call my URL (myApp://sample?param=1) using AJAX or JSONP so my App detects it?
(I've tried this with jQuery Ajax without a chance. I don't know if the intent-filter could handle Ajax requests.)

推荐答案

作为一种变通方法,可以识别意图指向服务器的链接,使用http://而不是对myApp://:

As a workaround, you can identify an intent pointing to your server link, using http:// instead of myApp:// :

<data android:host="yourhost.com" data android:path="/apath" android:scheme="http" />

有关...

<a href="http://yourhost.com/apath?param=1" id="myAppLink"></a>

如果您的应用程序存在,它会重定向到应用程序(用户需要确认的第一次),如果没有,它会叫,你主持一个页面,回答正确的桌面上的链接(使用PHP,JAVA, nodejs,或其他)。

If your app exists it will redirect to the app (the user will need to confirm the first time), if not, it will call the link where you host a page that will answer properly for desktop (using PHP, java, nodejs, or whatever).

这篇关于Android的:在后台意图过滤器和网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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