Manu Ram V
Manu Ram V

Reputation: 439

Deep linking opening both installed app on the android and playstore url

I am trying to acheive deeplinking through below javascrip piece of code, but the issue is if I have an installed app on android device it is opening both application and playstore url at sametime.Any suggestions to this?

<html>

<body>
<button onclick="launchAndroidApp()">Deep linking test</button>
<script>
function launchAndroidApp() {
            var test = window.open('DeeplinkingURL', "_self"); 
            setTimeout("window.location = 'Playstoreurl", 1000);
    }
    </script>
    </body>

    </html>

Upvotes: 1

Views: 2872

Answers (2)

ephemient
ephemient

Reputation: 204964

You can use a single URL using Android Intents with Chrome. For example, supposing DeeplinkingUrl="https://example.com/hello" and you expect it to be opened by the com.example.Hello application,

intent://example.com/hello
    #Intent;
    scheme=https;
    package=com.example.Hello;
    S.browser_fallback_url=market%3A%2F%2Fdetails%3Fid%3Dcom.example.Hello;
    end

without the spaces, will use com.example.Hello to launch https://example.com/hello if available, and open the Play store listing for the app otherwise. (Of course you could use http://play.google.com/store/apps/details?id= instead of market://details?id=.)

Upvotes: 1

clayjones94
clayjones94

Reputation: 2828

The setTimeout method simply gets executed regardless after 1 second. This is not the right approach to doing so, but if you are convinced on this method, I'd try using a try-catch.

try{
  window.open('DeeplinkingURL', "_self");
} catch {
  window.location = 'Playstoreurl';
}

Instead, I'd recommend using Branch. You can do this with their SDK for free and much cleaner.

Upvotes: 0

Related Questions