admin 管理员组

文章数量: 1086019

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.

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 :

  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.

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 user17534350user17534350
Add a ment  | 

2 Answers 2

Reset to default 2

I 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

本文标签:

Error[2]: Invalid argument supplied for foreach(), File: /www/wwwroot/roclinux.cn/tmp/view_template_quzhiwa_htm_read.htm, Line: 58
File: /www/wwwroot/roclinux.cn/tmp/route_read.php, Line: 205, include(/www/wwwroot/roclinux.cn/tmp/view_template_quzhiwa_htm_read.htm)
File: /www/wwwroot/roclinux.cn/tmp/index.inc.php, Line: 129, include(/www/wwwroot/roclinux.cn/tmp/route_read.php)
File: /www/wwwroot/roclinux.cn/index.php, Line: 29, include(/www/wwwroot/roclinux.cn/tmp/index.inc.php)