简体   繁体   中英

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. 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. Firefox works fine and Chrome does trigger the click event but do nothing. When I click the a href by myself(by my finger), it works. So now I have no idea if chrome can't let me open my app via code or just I use the wrong way.

Furthermore, when I change href to " https://www.google.com ", Both Firefox and Chrome work.

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

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

Chrome doesn't launch an external app for a given Intent URI in the following cases.

  • When the Intent URI is redirected from a typed in URL.
  • When the Intent URI is initiated without user gesture. (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. 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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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