目录

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 the association.

For detailed API introduction, refer to @ohos.multimodalAwareness.metadataBinding (Metadata Binding).

Overview

A third-party application can use metadata binding to map an App Linking link to the system application or service that calls the API. For example, when a user browses a product in an e-commerce application and saves a screenshot of the product image, the system records the mapping between the image and the App Linking link provided by the e-commerce application. When the user browses the image again and actively triggers the Celia screen recognition capability, the system reminds the user whether to return to the e-commerce application to view the product details. The reminder style is configured by Celia.

Demonstration Example

Available APIs

Name Description
submitMetadata(metadata: string): void; Passes the HarmonyOS App Linking link to be encoded from a third-party app to the multimodal awareness service, which determines the appropriate time to deliver the content to the system app that calls the encoding API.
on(type: 'operationSubmitMetadata', bundleName: string, callback: Callback<number>): void; Subscribes to system events to obtain encoded content. The app registers a callback, and the encoded content is returned when the event occurs.
off(type: 'operationSubmitMetadata', bundleName: string, callback?: Callback<number>): void; Unsubscribes from system events for obtaining encoded content. This API cancels the registered callback.

Constraints

How to Develop

  1. Import the related modules.

    import { metadataBinding } from '@kit.MultimodalAwarenessKit';
    import { BusinessError, Callback } from '@kit.BasicServicesKit';
  2. Define the metadata binding service callback and the bundle name. The function receives the encoded content returned.

    let callback : Callback<number> = (event: number) => {};
    let bundleName: string = 'com.example.app';
  3. Subscribe to the metadata binding service.

    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);
      // ...
    }
  4. Provide the App Linking link.

    let metadata: string = 'sample metadata';
    try {
      metadataBinding.submitMetadata(metadata);
      // ...
    } catch (err) {
      let error = err as BusinessError;
      console.error('Submit metadata error and err code is ' + error.code);
      // ...
    }
  5. Unsubscribe from the metadata binding service.

    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);
      // ...
    }