Search code examples
androidgoogle-playandroid-jetpack-composedeep-linking

How to open android app if app is installed or navigate to google play store by single link?


I need to implement this logic:

  1. user clicked on a link on an Android phone
  2. if my application is installed - the application opens
  3. if the application is not installed - open the Google Play page with my application

I need to use just 1 link. As I understand link should be looks like http://play.google.com/store/apps/details?id=<package_name>

I use compose navigation

So my question is how exactly should I implement this, what exactly should the link look like and should I add an assetlinks.json file to our website?


Solution

  • looks like you need an App-linking feature

    edit:

    1.Register some domain, e.g. bazinga.com

    2.Use App-linking for making your app a default specific-domain-url handler/opener

      <data android:scheme="http" />
      <data android:scheme="https" />
      <data android:host="bazinga.com" />
    

    note you can declare even one strict address, not whole domain, with android:android:pathPrefix (or similar)

    3.Prepare your domain behavior - e.g. https://bazinga.com/open_app url redirect to App Store or Google Play (this may be distinguished by User-Agent)

    4.On Android devices with app installed it will be opened and you may read an url which is delivered to Activity in Intent, or not if you don't need to (just enjoy autostart)

    PS. Note that you need autoVerify param and some additional file on server/domain side (confirming you aren't hijacking traffic of not-your domain) - this will make your app auto-open on url press. Without autoVerify (or verification failed?) you will create a deep linking solution - Android will ask user in which app url should be opened, your app or web browser, and there are "only once" and "always" options. In general 80% of this picks are web browser and "always", no matter of an app type... ehh, users..