• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.multimodalAwareness.metadataBinding (Metadata Binding)
2
3The **metadataBinding** module provides metadata binding–specific functions such as metadata transfer, event subscription, and event unsubscription.
4
5> **NOTE**
6>
7> 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.
8
9
10## Modules to Import
11```ts
12import { metadataBinding } from '@ohos.multimodalAwareness';
13```
14
15## submitMetadata(string)
16function submitMetadata(metadata: string): void;
17Transfers the metadata to be encoded to the MSDP. The MSDP determines whether to transfer the metadata to the system application or service that calls the encoding API.
18**System capability**: SystemCapability.MultimodalAwarness.metadataBinding
19
20**Parameters**
21
22| Name  | Type                            | Mandatory| Description                                                        |
23| -------- | -------------------------------- | ---- | ------------------------------------------------------------ |
24| metadata     | string                           | Yes  | Metadata to be encoded.|
25
26**Error codes**
27
28For details about the error codes, see [Metadata Binding Error Codes](errorcode-metadataBinding.md) and [Universal Error Codes](../errorcode-universal.md).
29
30| ID| Error Message                                                    |
31| -------- | ------------------------------------------------------------ |
32|32100001|Internal handling failed. Set Meta data to screenshot app fail.|
33
34**Example**
35
36```ts
37import { metadataBinding } from '@ohos.multimodalAwareness';
38import { BusinessError } from '@kit.BasicServicesKit';
39
40let metadata: string = "";
41try {
42  metadataBinding.submitMetadata(metadata);
43} catch (error) {
44  console.error("submit metadata error" + error);
45}
46```
47
48## metadataBinding.on('operationSubmitMetadata', string,  Callback\<number\>)
49metadataBinding.on(type: 'operationSubmitMetadata', bundleName: string, callback: Callback\<number\>): void;
50
51Subscribes to a system event to obtain the encoded metadata. The application needs to register a callback to return the encoded metadata when the registered system event occurs.
52**System capability**: SystemCapability.MultimodalAwarness.metadataBinding
53**Parameters**
54
55| Name  | Type                            | Mandatory| Description                                                        |
56| -------- | -------------------------------- | ---- | ------------------------------------------------------------ |
57|type| string|Yes|Event type. This parameter has a fixed value of **operationSubmitMetadata**, indicating the system application's attempt to obtain the encoded metadata.|
58|bundlename|string|Yes|Application bundle name.|
59|callback|Callback\<number\>|Yes|Callback used to return the encoded metadata.|
60
61**Error codes**
62
63For details about the error codes, see [Metadata Binding Error Codes](errorcode-metadataBinding.md) and [Universal Error Codes](../errorcode-universal.md).
64
65| ID| Error Message                                                    |
66| -------- | ------------------------------------------------------------ |
67|32100001|Internal handling failed. Service exception.|
68|32100004|Subscribe Failed.|
69
70**Example**
71```ts
72import { metadataBinding } from '@ohos.multimodalAwareness';
73import { BusinessError } from '@kit.BasicServicesKit';
74
75let bundleName: string = '';
76try {
77  metadataBinding.on('operationSubmitMetadata', bundleName, (event: number) =>{
78    if (event == 1) {
79      console.info("The screenshot request is intercepted and the app link is obtained");
80    }
81  });
82} catch (error) {
83  console.info("register screenshot event error");
84}
85```
86
87
88## metadataBinding.off('operationSubmitMetadata', string,  Callback\<number\>)
89metadataBinding.off(type: 'operationSubmitMetadata', bundleName: string, callback?: Callback\<number>): void;
90Unsubscribes from system events that are used to obtain the encoded metadata. The respective callback will be unregistered.
91**System capability**: SystemCapability.MultimodalAwarness.metadataBinding
92**Parameters**
93
94| Name  | Type                            | Mandatory| Description                                                        |
95| -------- | -------------------------------- | ---- | ------------------------------------------------------------ |
96|type|string|Yes|Event type. This parameter has a fixed value of **operationSubmitMetadata**, indicating the system application's attempt to obtain the encoded metadata.|
97|bundlename|string|Yes|Application bundle name.|
98|callback|Callback\<number\>|Yes|Callback used to return the encoded metadata.|
99
100**Error codes**
101
102For details about the error codes, see [Metadata Binding Error Codes](errorcode-metadataBinding.md) and [Universal Error Codes](../errorcode-universal.md).
103
104| ID| Error Message                                                    |
105| -------- | ------------------------------------------------------------ |
106|32100001|Internal handling failed. Service exception.|
107|32100005|Unsubscribe Failed.|
108
109**Example**
110
111```ts
112import { metadataBinding } from '@ohos.multimodalAwareness';
113import { BusinessError } from '@kit.BasicServicesKit';
114
115let bundleName: string = '';
116try {
117  metadataBinding.off('operationSubmitMetadata', bundleName, (evnet: number)=>{});
118} catch (error) {
119  console.error("unsubscript screenshot event" + error);
120}
121```
122