Reputation: 21
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.
Upvotes: 1
Views: 3591
Reputation: 11
<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/
Upvotes: 1