admin 管理员组文章数量: 1086019
So basically what I want is when the user clicks on a button on a mobile browser :
- If the app is already installed on the user's mobile, the app opens up.
- If the app is not installed, I want to redirect the user to the play store app/apple store from where the user can install that app.
Any solution/overview/idea/source would be highly appreciated.
NOTE: I want to do it using JavaScript or React and not java
Big THANKS for the help in advance !!
So basically what I want is when the user clicks on a button on a mobile browser :
- If the app is already installed on the user's mobile, the app opens up.
- If the app is not installed, I want to redirect the user to the play store app/apple store from where the user can install that app.
Any solution/overview/idea/source would be highly appreciated.
NOTE: I want to do it using JavaScript or React and not java
Big THANKS for the help in advance !!
Share Improve this question asked Jul 11, 2022 at 17:27 user17534350user175343502 Answers
Reset to default 2I found the javaScript solution for this and it is working for Instagram App.
But the issue I am facing is the "intent URL" present here for Instagram, I found it online but I am unable to find the "intent URL" for other apps present on the Play Store.
Any Help on how to find the intent URL for other apps on Play Store would be appreciated.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Deep Learning</title>
</head>
<body>
<div class="container">
<p id="case"></p>
<button onclick="openApp()">Open App</button>
</div>
<script>
var isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
(function () {
if (isMobile) {
document.getElementById("case").textContent =
"I am using Mobile browser";
} else {
document.getElementById("case").textContent =
"I am using Desktop/Web browser";
}
})();
function openApp() {
if (isMobile) {
const url =
"intent://instagram./#Intent;scheme=https;package=.instagram.android;end";
window.location.replace(url);
} else {
window.location.replace("https://www.instagram.");
}
}
</script>
</body>
</html>
What you trying to do is called deeplinking
, you can achieve that by accessing URI protocol
which is owned by your android application
For example:
example://www.myapp./anystring
To set your app available for URI opens. Add this receiver to your android manifest:
<receiver android:name=".DeepLinkReceiver">
<intent-filter >
<data android:scheme="example" android:host="www.myapp." />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>
In browser side just call this method:
window.open('example://www.myapp./anystring');
It will open window containing this string as url, so browser will automatically ask user to be redirected to your app
本文标签:
版权声明:本文标题:android - How to open mobile app after clicking a button in mobile browser (using javascriptreact) [Deep Linking] - Stack Overfl 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744094511a2532649.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论