Handling specific routes in Android M app links

Viewed 4989

Android M has added support for App links by creating a special assetlinks.json on the web server to delegate link handling to a mobile app.

For example, here's the content of such file:

[{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target": {
    "namespace": "android_app",
    "package_name": "com.costingtons.app",
    "sha256_cert_fingerprints": ["14:6D:E9:83:C5:73:06:50:D8:EE:B9:95:2F:34:FC:64:16:"
     "A0:83:42:E6:1D:BE:A8:8A:04:96:B2:3F:CF:44:E5"]
  }
}]

Currently, the relation is defined as common.handle_all_urls which means any url will be routed to the app.

I would like the app to open specific routes, for example https://costingtons.com/products/a-product would open in the app but https://costingtons.com would open the web version.

Apple Universal Links similar configuration file can define paths to be opened in the app, and the syntax supports pattern matching like /products/* etc.

Is there any way to do something like that with App Links in Android ?

3 Answers

@zmarties is right, the only thing you need to do is to make sure your Manifest.xml is configured to support https://yourdomain.com/product/* and not https://yourdomain.com/otherthings, https://yourdomain.com/otherthings will then open a web browser instead.

How to prove that?

ASOS and most e-commerce apps I know have app indexing enabled.

With ASOS Android app installed:

adb shell am start -a android.intent.action.VIEW \
    -c android.intent.category.BROWSABLE \
    -d "https://www.asos.com/men/shoes-boots-trainers/cat?cid=4209"

Will bring up a category screen in their Android app,

whereas, the following will open up web browsers:

adb shell am start -a android.intent.action.VIEW \
    -c android.intent.category.BROWSABLE \
    -d "https://www.asos.com/dummycrazyurl"
Related