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
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).
- 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.
- (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
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
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
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
- 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
- Configure app links on Android MainActivity by adding an IntentFilter per each domain/path/protocol you want to support.
Shared project
- 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.
Test
You can find the sample project full source code here.
For more information
- Android: https://docs.microsoft.com/en-us/xamarin/android/platform/app-linking
- iOS: https://developer.apple.com/library/ios/documentation/General/Conceptual/AppSearch/UniversalLinks.html
Happy App Linking!
6 Comments
Nice article.
What happens if your app is not installed on the user’s device? Where will the link take them?
will open up link in default browser!
Will open the browser and navigate to that url
This is quite cool! I never came across it, thanks for sharing 🙂
As usual, awesome tidbits from XamBoy/XamGirl team… Kudos !!
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.