Press "Enter" to skip to content

App Links in Xamarin Forms

As a mobile applications user sometimes we receive emails with url links that by clicking on them, they open an application instead of the browser. These are called App Links, in this article I will show you how to handle them in Xamarin Forms. I will use my own domain for my app links xamboy.com with the path hello, so that our sample application handles the url https://xamboy.com/hello.

Let’s start with iOS

Apple portal configuration

Before doing any code we need to setup something in the Apple Developer portal. (For that we will need a developer account).

  1. Go to App IDs section and click on your application

2. In the list of Application Services scroll to the bottom and click on Edit


3. Enable Associated Domains and Save.


Website configuration

In order to verify the domain association with the application, is necessary to upload a file in the website that defines this association.

  1. (For iOS) Need to create a file named apple-app-site-association. This file should contain the following json structure:
{
    "applinks": {
        "apps": [],
        "details": [
            {
                "appID": "CNAL8C4H5U.com.crossgeeks.applinkssample",
                "paths": [ "/hello/*"]
            }
        ]
    }
}

Example: https://www.xamboy.com/.well-known/apple-app-site-association

This file should be placed inside .well-known folder or at the root path of the website (https://yourdomain/.well-known/apple-app-site-association).

NOTES:

  • The appID is the combination of Prefix + (.) + ID


  • Paths is the definition of all the paths our application will handle if present on the url. For example in our case is https://xamboy.com/hello because we just defined /hello as a path in the apple-app-site-association file.
  • apple-app-site-association file shouldn’t have a file extension

2. (For Android) Need to create a Digital Assets file named assetlinks.json. There’s an online tool that assist you creating and testing this file here: https://developers.google.com/digital-asset-links/tools/generator.

It should contain the following json structure:

[
   {
      "relation":[
         "delegate_permission/common.handle_all_urls"
      ],
      "target":{
         "namespace":"android_app",
         "package_name":"com.crossgeeks.applinkssample",
         "sha256_cert_fingerprints":[
            "3E:5D:E5:3B:BC:5A:61:BC:9E:96:34:C7:C2:D6:9F:BB:32:3C:8E:C5:FD:CE:D2:76:4C:81:98:2F:41:12:15:DD"
         ]
      }
   }
]

Example: https://www.xamboy.com/.well-known/assetlinks.json

This file should be placed inside .well-known folder of the website (https://yourdomain/.well-known/assetlinks.json).

If you want to test that everything is working fine you can do it by using this url:

https://digitalassetlinks.googleapis.com/v1/statements:list?source.web.site= https://<YOUR WEB SITE ADDRESS>:&relation=delegate_permission/common.handle_all_urls

If everything is ok it should look similar to this:

Mobile app configuration

iOS project

  1. Go to the Entitlements.plist file, enable the property Associated Domain and add the domain of the website with the format applinks:yourdomain.com and applinks:*.yourdomain.com

Android project

  1. Configure app links on Android MainActivity by adding an IntentFilter per each domain/path/protocol you want to support. 
Copy here

Shared project

  1. In the App.cs file override the method OnAppLinkRequestReceived. This is where you handle what happens when your app is opened by an app link.

Copy here

Test

You can find the sample project full source code here.

For more information

Happy App Linking!

6 Comments

  1. Nice article.

    What happens if your app is not installed on the user’s device? Where will the link take them?

    • Jay Thaker Jay Thaker

      will open up link in default browser!

    • Rendy Rendy

      Will open the browser and navigate to that url

  2. julian julian

    This is quite cool! I never came across it, thanks for sharing 🙂

  3. SRINATH NANDURI SRINATH NANDURI

    As usual, awesome tidbits from XamBoy/XamGirl team… Kudos !!

  4. Miguel Muñoz Miguel Muñoz

    Hi Rendy,

    nice example, but I have a question,
    What happens when the project has SplashActivity and this has setted MainLauncher=true ?

    The IntentFilter is added in SplashActity or still in MainActiviy?

    Regards!

    Miiguel M L.

Comments are closed.