openharmony 鸿蒙 arkts-apis-camera-AutoDeviceSwitch

2026-08-25 浏览 (1)

Interface (AutoDeviceSwitch)

AutoDeviceSwitch inherits from AutoDeviceSwitchQuery and is used to enable or disable automatic camera switch. This capability can be used only on foldable devices. For details about the development, see Practices for Automatic Camera Switching (ArkTS).

It is recommended that the system automatically handle input device switching, session configuration, and parameter continuity during automatic camera switch. If the system detects that the zoom ranges of the two cameras are different during camera switching, it will notify the application through the isDeviceCapabilityChanged field in AutoDeviceSwitchStatus. However, the application still needs to handle the UX change. For example, for the zoom range adjustment, the application needs to call getZoomRatioRange to obtain data and update the UX. Therefore, AutoDeviceSwitch is more applicable to simplified UX interactions.

NOTE

  • The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
  • The initial APIs of this interface are supported since API version 13.

Modules to Import

import { camera } from '@kit.CameraKit';

enableAutoDeviceSwitch13+

enableAutoDeviceSwitch(enabled: boolean): void

Enables or disables automatic camera switch. You can use isAutoDeviceSwitchSupported to check whether the device supports automatic camera switch.

NOTE

This API is used only for foldable devices with multiple front cameras. In different fold states, the system can automatically switch to an available front camera. It does not enable automatic switching between front and rear cameras.

Atomic service API: This API can be used in atomic services since API version 19.

System capability: SystemCapability.Multimedia.Camera.Core

Parameters

NameTypeMandatoryDescription
enabledbooleanYesWhether to enable automatic camera switch. true to enable, false otherwise.

Error codes

For details about the error codes, see Camera Error Codes.

IDError Message
7400101Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameters verification failed.
7400102Operation not allowed.
7400103Session not config.
7400201Camera service fatal error.

Example

import { BusinessError } from '@kit.BasicServicesKit';

function enableAutoDeviceSwitch(session: camera.PhotoSession, isEnable: boolean): void {
  try {
    session.enableAutoDeviceSwitch(isEnable);
  } catch (error) {
    let err = error as BusinessError;
    console.error(`The enableAutoDeviceSwitch call failed, error code: ${err.code}, error message: ${err.message}`);
  }
}

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-oh-camera-capturesession-callbacks

openharmony 鸿蒙 arkts-apis-camera-OIS

openharmony 鸿蒙 capi-oh-camera-camera-devicequeryinfo

openharmony 鸿蒙 capi-oh-camera-camera-frameraterange

openharmony 鸿蒙 capi-oh-camera-camera-outputcapability

openharmony 鸿蒙 arkts-apis-camera-Photo

openharmony 鸿蒙 capi-oh-camera-camera-profile

openharmony 鸿蒙 capi-oh-camera-camera-manager

openharmony 鸿蒙 capi-oh-camera-previewoutput-callbacks

openharmony 鸿蒙 arkts-apis-camera-ManualExposureQuery

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/3KShXfYV