目录

CollaborationCamera (Device Interconnectivity Component)

This module provides the createCollaborationCameraMenuItems and CollaborationCameraStateDialog components, which need to be used together to implement distributed cross-device capabilities, for example, calling the camera of a phone from a PC/2-in-1 device.

The createCollaborationCameraMenuItems component is used to obtain a list of devices with required capabilities on the network. Users can then select a device to start the corresponding app. The CollaborationCameraStateDialog component is used to display a dialog box to show the status of the app on the remote device.

Deprecation notice: This API is deprecated since API version 5.0.0(12). You are advised to use CollaborationService instead.

Since: 4.0.0(10)

Modules to Import

import { CollaborationCameraStateDialog, createCollaborationCameraMenuItems, CollaborationCameraBusinessFilter} from '@kit.ServiceCollaborationKit';

createCollaborationCameraMenuItems(deprecated)

createCollaborationCameraMenuItems(businessFilter?: Array<CollaborationCameraBusinessFilter>): void

Device list selector, which needs to be called in the Menu component. It displays a list of devices with required capabilities on the network.

This method is a custom build function. Before using it, you need to understand @Builder.

Deprecation notice: This API is deprecated since API version 5.0.0(12). You are advised to use createCollaborationServiceMenuItems instead.

Model restriction: This API can be used only in the stage model.

Decorator: @Builder

System capability: SystemCapability.Collaboration.Camera

Device behavior differences: This API is supported on PCs/2-in-1 devices and tablets. On other device types, the device list cannot be displayed, and the device interconnectivity capability is unavailable.

Since: 4.0.0(10)

Parameters:

Parameter Type Mandatory Description
businessFilter Array<CollaborationCameraBusinessFilter> No

Capability type, which can be ALL, TAKE_PHOTO, SCAN_DOCUMENT, or IMAGE_PICKER.

The default value is ALL, indicating all capabilities are supported.

Example:

@Builder
myTestMenu() {
  Menu() {
    createCollaborationCameraMenuItems([CollaborationCameraBusinessFilter.ALL]);
  }
}

CollaborationCameraBusinessFilter(deprecated)

Enumerates capability types.

Deprecation notice: This API is deprecated since API version 5.0.0(12). You are advised to use CollaborationServiceFilter instead.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.Collaboration.Camera

Device behavior differences: This API is supported on PCs/2-in-1 devices and tablets. On other device types, the device list cannot be displayed, and the device interconnectivity capability is unavailable.

Since: 4.0.0(10)

Name Value Description
ALL 0 Matches all services.
TAKE_PHOTO 1 Matches cross-device photographing.
SCAN_DOCUMENT 2

Matches document scanning.

Since: 4.1.0(11)

IMAGE_PICKER 3

Matches the gallery selector.

Since: 4.1.0(11)

Example:

@Builder
myTestMenu() {
  Menu() {
    createCollaborationCameraMenuItems([CollaborationCameraBusinessFilter.ALL]);
  }
}

CollaborationCameraStateDialog(deprecated)

Displays a dialog box to show the status of the matched app on the remote device.

You need to implement the onState method and define this dialog box component on the page. The collaboration framework calls this method to complete the services.

This component is a custom component. Before using it, you need to understand @Component.

Deprecation notice: This API is deprecated since API version 5.0.0(12). You are advised to use CollaborationServiceStateDialog instead.

Model restriction: This API can be used only in the stage model.

Decorator: @Component

System capability: SystemCapability.Collaboration.Camera

Device behavior differences: This API is supported on PCs/2-in-1 devices and tablets. On other device types, the device list cannot be displayed, and the device interconnectivity capability is unavailable.

Since: 4.0.0(10)

[h2]onState(deprecated)

onState: (stateCode: number, buffer: ArrayBuffer) => void

Callback function used to receive data. stateCode indicates the service completion status, and buffer indicates the returned image data. You need to implement the onState method based on the status and image data, as well as the service logic.

Deprecation notice: This API is deprecated since API version 5.0.0(12). You are advised to use onState instead.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.Collaboration.Camera

Device behavior differences: This API is supported on PCs/2-in-1 devices and tablets. On other device types, the device list cannot be displayed, and the device interconnectivity capability is unavailable.

Since: 4.0.0(10)

Parameters:

Parameter Type Mandatory Description
stateCode number Yes Service completion status. For details, please refer to the error code table below.
buffer ArrayBuffer Yes If the operation is successful, the corresponding data is returned. If the operation fails, null is returned.

Error codes:

For details about the error codes, please refer to Error Codes.

ID Error Message
0 Success.
1001202001 The peer end cancels the operation.
1001202002 An error occurred within the collaborative framework.
1001202003 The local end cancels the operation.
1001202004 The device interconnectivity has been established.
1001202005 All images have been successfully sent back.
1001202006 Multiple images are being sent back.

[h2]build(deprecated)

build(): void

Default constructor of the struct. You cannot directly call this method.

Deprecation notice: This API is deprecated since API version 5.0.0(12). You are advised to use build instead.

Model restriction: This API can be used only in the stage model.

System capability: SystemCapability.Collaboration.Camera

Device behavior differences: This API is supported on PCs/2-in-1 devices and tablets. On other device types, the device list cannot be displayed, and the device interconnectivity capability is unavailable.

Since: 4.0.0(10)

Example:

Refer to the sample code below to call an app on the remote device.

For details about device interconnectivity, please refer to About This Kit.

import {
  createCollaborationCameraMenuItems,
  CollaborationCameraStateDialog,
  CollaborationCameraBusinessFilter
} from '@kit.ServiceCollaborationKit';
import { image } from '@kit.ImageKit';
import { hilog } from '@kit.PerformanceAnalysisKit';

@Entry
@Component
struct Index {
  @State picture: PixelMap | undefined = undefined;

  @Builder
  myTestMenu() {
    Menu() {
      createCollaborationCameraMenuItems([CollaborationCameraBusinessFilter.ALL]);
    }
  }

  build() {
    Column({ space: 20 }) {
      CollaborationCameraStateDialog({
        onState: (stateCode: number, buffer: ArrayBuffer): void => this.doInsertPicture(stateCode, buffer)
      })
      Button ('Use remote device to insert images')
        .type(ButtonType.Normal)
        .borderRadius(10)
        .bindMenu(this.myTestMenu)

      if (this.picture) {
        Image(this.picture)
          .borderStyle(BorderStyle.Dotted)
          .borderWidth(1)
          .objectFit(ImageFit.Contain)
          .height('80%')
          .onComplete((event) => {
            if (event != undefined) {
              hilog.info(0, 'MEMOMOCK', 'onComplete ' + event.loadingStatus);
            }
          })
      }
    }
    .padding(20)
    .width('100%')
    .alignItems(HorizontalAlign.Center)
  }

  doInsertPicture(stateCode: number, buffer: ArrayBuffer): void {
    if (stateCode != 0) {
      return;
    }
    let imageSource = image.createImageSource(buffer);
    imageSource.createPixelMap().then((pixelMap) => {
      this.picture = pixelMap;
    }).catch((error: Error) => {
      hilog.error(0, 'MEMOMOCK', 'Create pixel map failed: ' + error);
    }).finally(() => {
      imageSource.release();
    });
  }
}