Reputation: 21
I want to click a link that launches an app on Android. However, if the app is not installed, by default Android redirects to the Play store. I don't want this.
What I want is to be able to redirect to a custom webpage if the app is not installed. iOS seems to support this by using setTimeouts but according to this page https://vhudyma-blog.eu/open-mobile-application-from-the-browser/ there is no similar flow offered for Android. Thank you for your help.
if (isAndroid) {
const url =
"intent://instagram.com/#Intent;scheme=https;package=com.instagram.android;end";
// open the app
// if the app isn't installed, it seems we just go to the play store
window.location.replace(url);
} else if (isIOS) {
// go to the app
window.location.replace("instagram://");
// open the app store on a timeout. this will happen but not be seen if instagram has opened
setTimeout(() => {
window.location.replace(
"https://apps.apple.com/us/app/instagram/id389801252"
);
}, 10000);
} else {
// we're not in ios or android so just go to the website
window.location.replace("https://instagram.com");
}
Upvotes: 0
Views: 1512
Reputation: 2368
You might have a little luck with getInstalledRelatedApps()
const list = await navigator.getInstalledRelatedApps();
Here is an article about it: https://web.dev/get-installed-related-apps/
Even though it might not be too wildly supported.
Upvotes: 1