Table of contents

Created

13 December 2016

Requirements

Prerequisite knowledge

Basic familiarity of building Android application with AIR and using intent filters in the application. 

User level

{adcConfig::_[skillLevel]}

Introduction

Beginning with AIR 24, the developers can now use Android's App Links feature to associate an AIR application with their web domain. Android's App Link is a way to turn developer’s website links into app links. With Android 6.0 (API Level 23), a new mechanism has been introduced for opening up the application directly. This mechanism is similar to adding Universal Links on iOS, where if a normal HTTP/HTTPS link is clicked and the corresponding application is installed, users can be redirected to the application directly — just by tapping the link of the website.

For example, consider a website http://www.example.in. If the developer properly configures this website for App Links and its corresponding application is installed on a mobile device, the app opens up immediately when the link is clicked. Additionally, the developers also need to create intent filers in the application manifest for website URI.

Once set up, when a user clicks on a link of developer’s website from another application or webpage, this link opens up in the corresponding application immediately via the intent, provided the application is already installed — completely bypassing the browser. If the user doesn’t have the application installed, the link opens the website in a web browser.

How AIR supports App Links

To get an application ready for App Links, follow the steps listed below:

1. Create Intent Filter for URI in app.xml

To enable an app to handle links, use intent filters in app.xml under the manifest tag to
declare the URI patterns that the application handles.

The following example shows an intent filter that can handle links
to https://www.example.in and http://www.example.in.

<manifestAdditions> <![CDATA[ <manifest android:installLocation="auto"> … … <application android:enabled="true"> <activity android:excludeFromRecents="false"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> <intent-filter android:autoVerify="true"> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE"/> <data android:scheme="http" android:host="www.example.in"/> <data android:scheme="https" android:host="www.example.in"/> </intent-filter> </activity> </application> </manifest> ]]> </manifestAdditions>

Note:

  • Intent filters for App Links must declare an android:scheme value of http or https, or both. The filter should not declare any other scheme.
  • www.example.in should be replaced with the developer’s website address.
  • Set the android:autoVerify attribute to true in one of the intent filters to enable link verification for the application.

2. Publish a Digital Asset Links JSON file on web server to provide verification

For App Link verification, the developers need to declare an 'association with apps' by publishing a JSON file on web servers. When users install the app, App Link verification checks this file on the web server to make sure that the website allows application to open URLs on its behalf.

Only developer can create and upload this file, so the association of developer’s website with the app is secure.

Create a JSON format file with below content named as 'assetlinks.json'.

[{ "relation": ["delegate_permission/common.handle_all_urls"], "target": { "namespace": "android_app", "package_name": "air.Example", "sha256_cert_fingerprints": ["11:28:71:DB:73:9C:3A:BA:4A:EE:04:02:17:0B:D8:A0:A7:F2:D7:0E:65:CC:B5:3A:3F:6C:CD:C9:8A:2B:F1:47"] } }]

Note:    

  • The name of the JSON file must be 'assetlinks.json'
  • The JSON file should be kept at the following location:
https://domain[:optional_port]/.well-known/assetlinks.json
  • Make sure that the hosted JSON file is accessible over an HTTPS connection, regardless of whether the app's intent filter includes https or not.
  • To generate SHA256 fingerprints of the app’s signing certificate, use the 'keytool'. Use the following command to generate the fingerprint using the Java keytool:  
$ keytool -list -v -keystore my-release-key.keystore
  • To generate a keystore file and convert it into .p12 certificate to be used in AIR apps, use any one of the follwing commands:
1. $ keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000 2. $ keytool -importkeystore -srckeystore my-release-key.keystore -destkeystore my-release.p12 -srcstoretype JKS -deststoretype PKCS12 -deststorepass PASSWORD

The developers can receive the URL and its arguments in the ActionScript code by registering for NativeApplication InvokeEvent.

For example: NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, invokeHandler);

To read more about the ActionScript InvokeEvent, see the ActionScript Reference for InvokeEvent.

Where to go from here

For additional reference, read Android's documentation on Handling App Links.