目录

Starting an App Using the App Link Capability of App Linking

Use Cases

With the app link capability of App Linking, the system redirects users to specific content in the target app based on the passed URI (HTTPS link). Unlike Deep Linking, App Linking allows users to smoothly access the content whether or not the target app is installed.

For example, once you have integrated the scan-to-access service by using the app link capability of App Linking, users can scan the QR code or barcode of your app through system-level scanning entry points such as the scan button on the control panel. This takes them directly to the corresponding service page of your app, providing a seamless, one-step experience.

This capability applies only to HarmonyOS apps with API version 5.0.0(12) or later. If you are developing an atomic service, please refer to Using an Atomic Service Link for Atomic Service Redirection.

Mechanisms

Constraints

Phones, PCs/2-in-1 devices, and tablets are supported. Starting from version 5.1.1(19), this capability is also supported on TVs.

Prerequisites

You have enabled App Linking.

Development Process

Party Procedure
Cloud-side development Enable App Linking.
Cloud-side development Associate a domain name with your app.
Cloud-side development Create an associated website domain name for your app in AppGallery Connect.
App-side development Configure the associated website domain name in the module.json5 file.
App-side development Process the passed link.
Front-end development

Develop the HTML5 web page corresponding to the passed link. If the app is not installed, this web page will be displayed when the link is tapped.

Note: This document focuses on the development of HarmonyOS apps and will not detail web page development.

App-side development Verify the app launch effect.

[h2]Associating a Domain Name with Your App

Perform the following operations on the domain name server (DNS) of your website. When you create an associated website domain name for your app in AppGallery Connect, AppGallery Connect will use the following file to identify apps belonging to the domain name, making the links more secure and reliable.

  1. Create a domain name configuration file applinking.json as follows:

    {
     "applinking": {
       "apps": [
         {
           "appIdentifier": "1234567",
           "index": 1
         },
         {
           "appIdentifier": "7654321",
           "index": 2
         }
       ]
     }
    }

    A website domain name can be associated with multiple apps if you add multiple appIdentifier elements to the apps list. Each appIdentifier element corresponds to an app.

    Parameter Mandatory Type Description
    appIdentifier Yes String App ID generated during app creation. For details about how to obtain the app ID, please refer to Viewing App Information.
    index No Integer

    If multiple apps match based on App Linking, you can configure the index field to specify which app to launch.

    The value range of index is [-100,100]. Values can be duplicate but cannot be empty. A larger value indicates a higher priority.

    - If multiple apps match but none of them is configured with the index field, the system launches all the matched apps and displays a dialog box asking the user to select one.

    - If multiple apps match and the index field is configured for some or all of them, the system launches the app with the highest index value. If more than one app shares the highest index value, the system launches these apps simultaneously and displays a dialog box asking the user to select one.

    Since: 6.1.0(23)

  2. Place the applinking.json configuration file in the following directory on the DNS: https://domain.name/.well-known/applinking.json. For example, if the domain name of your server is www.example.com, place the applinking.json file in the following directory:

    https://www.example.com/.well-known/applinking.json

[h2]Creating an Associated Website Domain Name for Your App in AppGallery Connect

To use the app link capability of HarmonyOS, you need to create an associated website domain name for your HarmonyOS app.

  1. Sign in to AppGallery Connect and click Development and services.

  2. Click the project to which your HarmonyOS app belongs.

  3. In the navigation tree, choose Grow > App Linking > App Link, and on the page displayed, click New.

  4. Enter the domain name you have associated with your app, for example, https://www.example.com. An exact domain name without special characters shall be used.

    Do not add a slash (/) to the end of the domain name. For example, https://www.example.com/ is not supported.

  5. After the setting is complete, click Release. AppGallery Connect will check whether the apps contained in the configuration file of the website domain name overlap with the apps in the project.

    After an app link is released, AppGallery Connect will obtain the configuration file from the DNS every 24 hours and check whether the file contains any apps in the project.

    For example, if you create an app link at 17:21 on April 7, AppGallery Connect may obtain the new configuration file from the DNS at 17:30 on April 8, check whether the file contains any apps in the project, and update the release status.

    • If the configuration file of the domain name contains any app in the project, the release is successful. You can click View to view the information about the apps associated with the domain name.

    • If the verification is in progress, the status is Publishing.

    • If the configuration file does not contain any app in the project, the release fails. You can click View to check the release failure cause.

[h2]Configuring the Associated Website Domain Name in the module.json5 File

Configure the following information in the module.json5 file of your app to declare the domain name associated with the app and enable domain verification. If the URL matches the host and path rules defined in the module.json5 file, your app can be launched.

By default, the skills field contains a skill object, which is used to identify the app entry. App redirection links cannot be configured in the skill object. Instead, you need to create a separate skill object.

If multiple redirection scenarios are involved, create different skill objects under skills. Otherwise, the configuration will not take effect.

For example, the configuration below declares that the app is associated with the domain name www.example.com.

{
  "module": {
    "abilities": [
      {
        "name": "EntryAbility",
        "srcEntry": "./ets/entryability/EntryAbility.ets",
        "icon": "$media:icon",
        "label": "$string:EntryAbility_label",
        // Set exported to true. If exported is set to false, only authorized system apps can start the target app.
        "exported": true,
        "startWindowIcon": "$media:icon",
        "startWindowBackground": "$color:start_window_background",
        "skills": [
          {
            "entities": [
              "entity.system.home"
            ],
            "actions": [
              // Since version 5.1.1(19), "actions" must be set to "ohos.want.action.home". For 5.1.0(18) and earlier versions, "actions" should be set to "action.system.home".
              "ohos.want.action.home"
            ]
          },
          {
            "entities": [
              // entities must contain "entity.system.browsable".
              "entity.system.browsable"
            ],
            "actions": [
              // actions must contain "ohos.want.action.viewData".
              "ohos.want.action.viewData"
            ],
            "uris": [
              {
                // scheme must be set to https.
                "scheme": "https",
                // host must be set to the associated website domain name.
                "host": "www.example.com",
                // path is optional, which indicates the directory on the DNS, such as path1 in www.example.com/path1.
                // If the app supports only specific paths, provide those paths here to prevent unsupported paths from triggering the app.
                "path": "path1"
              }
            ],
            // domainVerify must be set to true.
            "domainVerify": true
          }
          // If other redirection capabilities are involved, such as push message– and NFC-based redirection, add a skill object to prevent conflicts with App Linking.
        ]
      }
    ]
  }
}

Verifying the App Launch Effect

  1. Manually sign your app.

    Do not use the automatic signing function of DevEco Studio. Otherwise, the app cannot be started.

  2. Compile, package, and install the app to the debugging device.

  3. Verify the effect of app launch using the app link capability of App Linking.

[h2]Starting the App Through the System Browser or ArkWeb

ArkWeb deeply integrates App Linking. When a user taps a link in the system browser or on an embedded web page in an app that integrates ArkWeb, the system preferentially starts the target app through App Linking, and displays the corresponding content in the app. However, there are certain restrictions:

  1. If the domain name of the web page that the user browses is the same as that of the link tapped, the system will open the link in the system browser or the ArkWeb component to maintain a consistent browsing experience.

  2. If the domain name of the web page is different from that of the link (for example, one is example.com while the other is app.example.com), the system will preferentially start the target app using App Linking and display the corresponding content in the app.

FAQs

[h2]What should I do if the value of skills in the module.json5 file of the app is incorrect?

Check whether the domain name of the app in the "host" field is the same as that configured in AppGallery Connect.

[h2]What should I do if the server of my website is incorrectly configured?

Follow the instructions below:

  1. Check the JSON configuration file of the server and ensure that the value of appIdentifier is correct.

  2. Check whether the applinking.json file is stored in the correct directory (.well-known). Use a browser or other ways to access the JSON file at https://your.domain.name/.well-known/applinking.json and ensure that the file is accessible.

[h2]What should I do if the system has not completed domain verification?

Follow the instructions below:

  1. After installing the app on the device, wait at least 20 seconds to ensure that the system completes domain verification.

  2. If the network is disconnected or weak, the domain verification may fail, and the system will conduct the verification again within 24 hours.

[h2]How do I check whether domain verification is successful?

To view the app domain name verification result, click Terminal in DevEco Studio and run the following command to query the result:

hdc shell hidumper -s AppDomainVerifyManager

If the verification is successful, you will see the success message like the output below.

BundleName:
  appIdentifier:123456789
   domain verify status:
    https://www.example.com:success

[h2]What should I do if I cannot use App Linking to open a pre-installed app when I start my device for the first time?

The system verifies the domain name of a pre-installed app within 20 minutes after the device is started for the first time. If the device cannot access the Internet in this period, the domain verification may fail. In this case, restart your device or try again after 24 hours. The system will verify the domain name of the pre-installed app again after you restart the device or after 24 hours.

[h2]What should I do if the content is not updated in a timely manner when I access the content delivery network (CDN)?

The CDN cache duration is 10 minutes. Wait for a while and access the CDN again.

[h2]How are apps and domain names mapped?

They are in a many-to-many relationship. An app can be associated with multiple domain names, and a domain name can be associated with multiple apps.