【发布时间】:2018-02-19 16:26:10
【问题描述】:
我正在开发 Android 应用程序并尝试使用浏览器中的 a href 打开我的应用程序。我试了几次,发现了一些有趣的东西(或者只是我不够聪明)。
当我检测到使用 Android Mobile 的用户时,我会触发一个 href 的点击事件,然后我的应用应该会打开。 Firefox 工作正常,Chrome 确实触发了点击事件,但什么也不做。当我自己(通过我的手指)单击 a href 时,它可以工作。所以现在我不知道chrome是不能让我通过代码打开我的应用程序还是我使用了错误的方式。
此外,当我将 href 更改为“https://www.google.com”时,Firefox 和 Chrome 都可以使用。
<a id="goToMyApp" href="intent://myHost/#Intent;package=myPackage;scheme=https;end;">
click me</a>
<script type="text/javascript">
var goToMyApp = document.getElementById("goToMyApp");
if (navigator.userAgent.match(/Android/)) {
setTimeout("goToMyApp.click()",1000);
}
</script>
这是我在 AndroidManifest.xml 中的意图过滤器,但我认为没有问题。
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="https" android:host="myHost" android:path="/"/>
</intent-filter>
有人对此有任何想法吗?
编辑:
我在这里再次阅读了关于Android Intents with Chrome 的文档:https://developer.chrome.com/multidevice/android/intents,最后看到了页面底部的 cmets。
在以下情况下,Chrome 不会为给定的 Intent URI 启动外部应用程序。
- 当 Intent URI 从输入的 URL 重定向时。
- 在没有用户手势的情况下启动 Intent URI。 (这是我想做的)
我认为是因为安全政策,Chrome 不会让页面通过代码启动意图。这就解释了为什么我可以通过手势而不是代码打开我的应用程序。
我会留下这个问题,希望它可以帮助其他尝试做同样事情的人。
【问题讨论】:
标签: javascript android google-chrome android-intent intentfilter