简体   繁体   English

单击移动浏览器中的按钮后如何打开移动应用程序(使用javascript / react)[深度链接]

[英]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 :所以基本上我想要的是当用户点击移动浏览器上的按钮时:

  1. If the app is already installed on the user's mobile, the app opens up.如果该应用程序已安装在用户的手机上,则会打开该应用程序。
  2. 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.如果未安装该应用程序,我想将用户重定向到用户可以安装该应用程序的 Play 商店应用程序/苹果商店。

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.

相关问题 使用深度链接从 Web 浏览器打开 ios/android 应用程序时,如何将数据传递到移动应用程序 - When using deep linking to open an ios/android application from web browser , How can i pass data to the mobile application 如何在Javascript上打开移动浏览器? - How to open mobile browser on Javascript? 如何使用 javascript 或 html 打开移动 chrome 浏览器 - how to open mobile chrome browser with javascript or html 如果通过移动浏览器安装,则使用Facebook App打开粉丝页面 - Open a fanpage using Facebook App if installed via mobile browser 通过单击按钮在移动设备中加载现有的Android App - Loading Existing Android App in mobile by clicking button 如何使用JavaScript在WebView内打开移动浏览器上的窗口(弹出式窗口)? - How to open a window(poup) on mobile browser from inside a webview using javascript? 如果移动浏览器未打开或未激活,则在 Javascript/jQuery 中检测 - Detect in Javascript/jQuery if mobile browser is not open or active 通过浏览器打开本机应用(非移动) - Open native app from browser (not mobile) 如何在移动 chrome 浏览器中将 Phantom 钱包连接到 React App? - How to connect Phantom wallet to React App in mobile chrome browser? 使用javascript(无意图)打开移动应用(如果已安装) - Open mobile app (if installed) using javascript (without intent)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM