简体   繁体   English

通过Chrome打开Android应用a href-Click事件

[英]Open Android App via Chrome a href - Click event

I'm working on Android App and trying to use an a href from browser to open my app. 我正在使用Android应用,正在尝试使用浏览器中的href打开我的应用。 I tried several times and found something interesting (or just I am not smart enough). 我尝试了几次,发现了一些有趣的东西(或者只是我不够聪明)。

When I detect the user using Android Mobile, I will trigger click event of a href then my app should be opened. 当我使用Android Mobile检测到用户时,我将触发href的click事件,然后应打开我的应用。 Firefox works fine and Chrome does trigger the click event but do nothing. Firefox工作正常,Chrome确实触发了点击事件,但无济于事。 When I click the a href by myself(by my finger), it works. 当我自己(用手指)单击a href时,它会起作用。 So now I have no idea if chrome can't let me open my app via code or just I use the wrong way. 所以现在我不知道chrome是否不能让我通过代码打开我的应用程序,或者只是我使用了错误的方式。

Furthermore, when I change href to " https://www.google.com ", Both Firefox and Chrome work. 此外,当我将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>

And here is my intent-filter in AndroidManifest.xml, but I don't think there is the problem. 这是我在AndroidManifest.xml中的intent-filter,但是我认为没有问题。

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

Does anyone have any idea about this? 有人对此有任何想法吗?

EDIT: 编辑:

I read the document about Android Intents with Chrome again right here: https://developer.chrome.com/multidevice/android/intents and finally saw the comments at the bottom of page. 我在这里再次阅读了有关Android Intents with Chrome的文档: https : //developer.chrome.com/multidevice/android/intents ,最后在页面底部看到了注释。

Chrome doesn't launch an external app for a given Intent URI in the following cases. 在以下情况下,Chrome不会针对给定的Intent URI启动外部应用。

  • When the Intent URI is redirected from a typed in URL. 从输入的URL重定向Intent URI时。
  • When the Intent URI is initiated without user gesture. 在没有用户手势的情况下启动Intent URI时。 (This one is what I trying to to do) (这是我想要做的)

I think it is because of the safety policy that Chrome won't let page start an intent by code. 我认为是出于安全政策,Chrome不允许网页通过代码启动意图。 And that explain why I can open my app by gesture but not by code. 这就解释了为什么我可以通过手势而不是代码打开我的应用程序。

I will leave this question a hope it can help other people trying to do the same thing. 我将这个问题留给希望,它可以帮助其他尝试做同样事情的人。

<intent-filter>
<data android:scheme="anton" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>

The answer is explained in further detail over here: https://appstudio.ca/blog/index.php/2017/09/11/open-the-android-app-using-the-link/ 答案在这里进行了更详细的解释: https : //appstudio.ca/blog/index.php/2017/09/11/open-the-android-app-using-the-link/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM