[英]How to open mobile app after clicking a button in mobile browser (using javascript / react) [Deep Linking]
So basically what I want is when the user clicks on a button on a mobile browser :所以基本上我想要的是当用户点击移动浏览器上的按钮时:
Any solution/overview/idea/source would be highly appreciated.任何解决方案/概述/想法/来源都将受到高度赞赏。
NOTE: I want to do it using JavaScript or React and not java注意:我想使用 JavaScript 或 React 而不是 java
Big THANKS for the help in advance !!非常感谢您的提前帮助!
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:您尝试执行的操作称为deeplinking
,您可以通过访问您的 android 应用程序拥有的URI protocol
来实现这一点,例如:
example://www.myapp.com/anystring
To set your app available for URI opens.将您的应用设置为可用于 URI 打开。 Add this receiver to your android manifest:将此接收器添加到您的 android 清单中:
<receiver android:name=".DeepLinkReceiver">
<intent-filter >
<data android:scheme="example" android:host="www.myapp.com" />
<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.com/anystring');
It will open window containing this string as url, so browser will automatically ask user to be redirected to your app它将打开包含此字符串作为 url 的窗口,因此浏览器将自动要求用户重定向到您的应用程序
I found the javaScript solution for this and it is working for Instagram App.我为此找到了 javaScript 解决方案,它适用于 Instagram 应用程序。
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.但我面临的问题是此处为 Instagram 提供的“意图 URL”,我在网上找到了它,但我无法找到 Play 商店中其他应用程序的“意图 URL”。
Any Help on how to find the intent URL for other apps on Play Store would be appreciated .任何有关如何在 Play 商店中查找其他应用程序的意图 URL 的帮助将不胜感激。
<!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.com/#Intent;scheme=https;package=com.instagram.android;end";
window.location.replace(url);
} else {
window.location.replace("https://www.instagram.com");
}
}
</script>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.