Metadata Binding Development
Overview
Metadata binding allows the system to map the content browsed by the current user to the App Linking link provided by a third-party application and save their mapping.
For details about the APIs, see the MetadataBinding API Reference.
When to Use
Third-party applications can use the metadata binding function to map the App Linking link to the desired content for easy access at a later time. For example, when a user is browsing a product in an e-commerce app and takes a screenshot of that product to save it, the system will record the mapping between the screenshot and the App Linking link provided by the e-commerce app. When the user views the screenshot again, the system will remind the user of whether to return to the e-commerce app to view the product details.
Demonstration Example

Available APIs
- The initial APIs of this module are supported since API version 18. Newly added APIs will be marked with a superscript to indicate their earliest API version.
- This module supports the metadata binding function.
| Name | Description |
|---|---|
| submitMetadata(metadata: string): void; | Passes the App Linking link mapped to the encoded metadata to Multimodal Awareness Kit, which then forwards the link to the system application that calls the encoding API at an appropriate time. |
| on(type: 'operationSubmitMetadata', bundleName: string, callback: Callback<number>): void; | Subscribes to system events that are used to obtain the encoded metadata. The application needs to register a callback to return the encoded metadata when the registered system event occurs. |
| off(type: 'operationSubmitMetadata', bundleName: string, callback?: Callback<number>): void; | Unsubscribes from system events that are used to obtain the encoded metadata. The respective callback will be unregistered. |
Constraints
- The maximum length of an App Linking link is 128 bytes.
How to Develop
-
Import the related modules.
import { metadataBinding } from '@kit.MultimodalAwarenessKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { Callback } from '@kit.BasicServicesKit'; -
Define the callback used to return the encoded metadata and the bundle name.
let callback : Callback<number> = (event: number) => {}; let bundleName: string = ''; -
Subscribe to system events that are used to obtain the encoded metadata.
try { metadataBinding.on('operationSubmitMetadata', bundleName, callback); console.info("on succeeded"); } catch (err) { let error = err as BusinessError; console.error("Register event error and err code is " + error.code); } -
Configure the App Linking link.
// The application first enables the App Linking service, obtains the App Linking service, and then provides the service API for the link memory service let applink: string = ""; try { metadataBinding.submitMetadata(applink); } catch (err) { let error = err as BusinessError; console.error("Submit metadata error and err code is " + error.code); } -
Unsubscribe from system events that are used to obtain the encoded metadata.
try { metadataBinding.off('operationSubmitMetadata', bundleName, callback); console.info("off succeeded"); } catch (err) { let error = err as BusinessError; console.error("Unregister event error and err code is " + error.code); }