Huawei App Linking or Deep Linking
Introduction
App Linking or deep linking is a technology which enable businesses to provide ease of access for their potential services.
Deep links are links which re-direct users directly to a specific app or application feature instead of a website or store.
They are used to re-direct users straight to in-app locations, saving the users time and energy.
Deep linking does this by specifying a custom URL scheme (iOS Universal Links) or an intent URL (on Android devices) that opens your app if it’s already installed. Deep links can also be set to direct users to specific events or pages.
Huawei App Linking leverage developers/users to create cross platform links which can work as defined and can be distributed via multiple channels to users.
When the user taps the link, it will be re-directed to the specified in-app content.
Huawei App Linking has multiple functions:
1. Support for deferred deep links
2. Link display in card form
3. Data statistics
Huawei App Linking supports the link creation in multiple ways:
1. Creating a link in AppGallery Connect
2. Creating a link by calling APIs on the client
3. Manually constructing a link
Creating a link in AppGallery Connect
We will be focusing on the Huawei App linking capabilities to create the deep links for our Android application through Huawei AppGallery Connect.
Use Case
There could be multiple use cases for this capability, however I will throw some light on a use case which is most commonly adapted by the applications with complex UX and high transmission between different in-app pages.
In this scenario one application shares the link between counter applications to re-direct to in-app content of a third application.
We will have an application which shares the app link at one end to another (It can be a simple chat platform capability). At the receiver end, user can click on the link and directly navigate to the specific in-app content.
Working
Following are the steps to develop this scenario
1. Development of news application which will be deployed locally.
2. Development of share application which will be deployed locally.
3. Integration of Huawei App Linking Api’s to receive the link and re-direct to the in-app content of news app.
4. Enabling the App linking service in AppGallery Connect.
5. Creating deep link through AppGallery Connect.
Development Overview
1. Must have a Huawei Developer Account
2. Must have Android Studio 3.0 or later
3. Must have a Huawei phone with HMS Core 4.0.2.300 or later
4. EMUI 3.0 or later
Software Requirements
1. Java SDK 1.7 or later
2. Android 5.0 or later
Preparation
1. Create an app or project in Android Studio.
2. Create an app and project in the Huawei AppGallery Connect.
3. Provide the SHA Key and App Package name of the project for which you want the App Linking to be done (Example: News application)
4. Download the agconnect-services.json file and paste to the app folder of your android studio.
Integration
· Add below to build.gradle (project)file, under buildscript/repositories and allprojects/repositories.
Maven {url ‘http://developer.huawei.com/repo/'}
· Add below to build.gradle (app) file, under dependencies to use the App Linking SDK.
dependencies{
// Import the SDK.
implementation ‘com.huawei.agconnect:agconnect-applinking:1.4.1.300’
}
News Application
News application is developed with multiple content and complex UX to show the capability of the Huawei App Linking.
I will highlight some if the important code blocks for this application.
Main Activity
This activity is the entry point for the application which will have the navigation tab to handle the multiple news categories.
Also, it receives the App Link, read it and re-direct it to the corresponding content.
Creating a link in AppGallery Connect to directly open the Science tab for the News Application through a link
1. Login to AppGallery Connect.
2. Choose My Projects > NewsWorld(App Linking).
3. Go to>Growing > App Linking>Enable now
4. Once you enable the app linking for your project by setting up the country and region choose URL prefix>Add URL prefix
Add URL prefix, which is a free domain name provided by AppGallery Connect with a string.
Tip: URL prefix should be unique and can contain only lowercase letters and digits.
Select Set domain name option and then click on Next button.
The following page will be displayed.
5. Click App Linking and then click Create App Linking for deep linking purpose. It is required to directly navigate to specific in-app content from a different application.
6. It will suggest short link by itself or you can customize it as shown below.
7. Click on Next button and set the deep link.
App Linking name: deep link name.
Default deep link: deep link used to open an app.
Android deep link: deep link preferentially opened on an Android device.
iOS deep Link URL: deep link preferentially opened on an iOS device.
Tip 1: Link name and Default deep link can be same and follow as https://domainname.com/xxx
Where “domainname” is URLprefix which we set above and “xxx” is specific in-app content page to re-direct.
Tip 2: You can customize the deep link, which is different from the URL prefix of the link.
Once done, click on Next button.
9. Select Set Android link behaviour for your Android application as below.
We will choose “Open in app” as we want our application to open directly as application.
Select your application from the Add Android app menu.
Redirect user to AppGallery page if the application is not installed on the device.
Tip: Ensure that the App Store ID and team ID have been configured. If they are not configured, add them as prompted.
Once done, click on Next button.
10. We have set the deep link for our news application and it will re-direct to in-app content tab (science) every time when it is shared from our share application.
To check the details and use the link we will navigate to view details
11. We will use short App link for our App Linking use case. It will re-direct the user to Science tab of news application from our shared link through different tab.
Receiving Links of App Linking
When a user is directed to the target content after tapping a received link of App Linking, your app can call the API provided by the App Linking SDK to receive the tapped link and obtain data passed through the link.
Add an Intent Filter to manifest file
Add intent filter to activity which will receive and process the link.
We will add this for Main activity for our use case.
Receive the link in our Main activity
Add below code to your activity to receive and process the link.
LinkMyApps Application
This is another application trough which we will share the link to re-direct to the in-app content of our News application.
Chat Activity
It’s very simple activity which has one text box and one share button to share the links.
activity_chat.xml
View activity
Results
Tips and Tricks
1. URL prefix should be unique and can contain only lowercase letters and digits.
2. Link name and Default deep link can be same and follow as https://domainname.com/xxx
Where “domainname” is URLprefix which we set above and “xxx” is specific in-app content page to re-direct.
3. You can customize the deep link, which is different from the URL prefix of the link.
4. Ensure that the App Store ID and team ID have been configured. If they are not configured, add them as prompted.
Conclusion
This article focuses on the Huawei App linking capabilities and explains to create deep links using AppGallery Connect. Featured use case demonstrate the ability to share a link between two ends points of an application to access the in-app content of an news application.
Reference