Search code examples
androiddeep-linkingandroid-instant-appsandroid-deep-link

How to configure web app fallback for instant app


I'm having an android app that is having an instant app version. My instant app can be launched & run without installation from deep link. This is how my deep domain assetlinks.json looks like:

[{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target": {
    "namespace": "android_app",
    "package_name": "com.<app name>",
    "sha256_cert_fingerprints":
    ["<app fingerprint>"]
  }
}]

It is working fine, but what I want to achieve is to have "fallback" web application when user would have disabled instant apps or have older device. I've tried to host react.js web application on this domain with assetlinks.json file in public folder(to make it available) and it was not working at all, android phone treated this domain as usual website and instant app was not launching like on previous configuration. Same thing goes for hosting empty index.html file. It is also breaking instant app invocation process. Any ideas this this can be configured ?

this is how instant app invocation screen looks like


Solution

  • Alright, I've managed to find a solution, it is pretty easy one. My deep links most of the time have data passed as path such as /type/value. The solution is to create clear index.html file with javascript attached like this:

      <script>
        window.location.href = '<FALLBACK WEB APP URL>' + 
        window.location.pathname;
      </script>
    

    This code extracts path from the deep link and adds it to web app link. Next, index.html needs to be served for every folder of deep domain, but domain needs to also allow to read assetlinks.json file if needed. This solution work pretty well with instant apps - it is not breaking invocation process, and is is also compatible with iOS AppClips.