1# Metadata Binding Development 2<!--Kit: Multimodal Awareness Kit--> 3<!--Subsystem: MultimodalAwareness--> 4<!--Owner: @dilligencer--> 5<!--Designer: @zou_ye--> 6<!--Tester: @judan--> 7<!--Adviser: @hu-zhiqiong--> 8 9## Overview 10 11Metadata binding allows the system to map the content browsed by the current user to the [App Linking link](https://developer.huawei.com/consumer/en/doc/harmonyos-guides/applinking-introduction) provided by a third-party application and save their mapping. 12 13For details about the APIs, see the [MetadataBinding API Reference](../../reference/apis-multimodalawareness-kit/js-apis-awareness-metadataBinding.md). 14 15## When to Use 16 17Third-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. 18 19## Available APIs 20 21| Name | Description | 22| ------------------------------------------------------------ | -------------------------------------- | 23| [submitMetadata](../../reference/apis-multimodalawareness-kit/js-apis-awareness-metadataBinding.md#metadatabindingsubmitmetadata)(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.| 24| [on](../../reference/apis-multimodalawareness-kit/js-apis-awareness-metadataBinding.md#metadatabindingonoperationsubmitmetadata)(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.| 25| [off](../../reference/apis-multimodalawareness-kit/js-apis-awareness-metadataBinding.md#metadatabindingoffoperationsubmitmetadata)(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.| 26 27## Constraints 28 29 - The maximum length of an App Linking link is 99 bytes. 30 31## How to Develop 32 331. Import the related modules. 34 35 ```ts 36 import { metadataBinding } from '@kit.MultimodalAwarenessKit'; 37 import { BusinessError } from '@kit.BasicServicesKit'; 38 import { Callback } from '@ohos.base'; 39 ``` 40 412. Define the callback used to return the encoded metadata. 42 43 ``` 44 let callback : Callback<number> = (event: number) => {}; 45 ``` 46 473. Subscribe to system events that are used to obtain the encoded metadata. 48 49 ``` 50 let bundleName: string = ''; 51 try { 52 metadataBinding.on('operationSubmitMetadata', bundleName, this.callback); 53 console.info("on succeeded"); 54 } catch (err) { 55 let error = err as BusinessError; 56 console.error("Register event error and err code is " + error.code); 57 } 58 ``` 59 604. Configure the App Linking link. 61 62 ``` 63 let metadata: string = ""; 64 try { 65 metadataBinding.submitMetadata(metadata); 66 } catch (err) { 67 let error = err as BusinessError; 68 console.error("Submit metadata error and err code is " + error.code); 69 } 70 ``` 71 725. Unsubscribe from system events that are used to obtain the encoded metadata. 73 74 ``` 75 try { 76 metadataBinding.off('operationSubmitMetadata', bundleName, this.callback); 77 console.info("off succeeded"); 78 } catch (err) { 79 let error = err as BusinessError; 80 console.error("Unregister event error and err code is " + error.code); 81 } 82 ``` 83