• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Interface (AutoDeviceSwitch)
2<!--Kit: Camera Kit-->
3<!--Subsystem: Multimedia-->
4<!--Owner: @qano-->
5<!--SE: @leo_ysl-->
6<!--TSE: @xchaosioda-->
7
8> **NOTE**
9>
10> - 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.
11> - The initial APIs of this interface are supported since API version 13.
12
13AutoDeviceSwitch inherits from [AutoDeviceSwitchQuery](arkts-apis-camera-AutoDeviceSwitch.md).
14
15It is used to enable or disable automatic camera switch. This class inherits from [AutoDeviceSwitchQuery](arkts-apis-camera-AutoDeviceSwitch.md).
16
17It is recommended that the system completes input device switch, session configuration, and parameter connection during automatic camera switch. If the system detects that the zoom ranges of the two cameras are different, it notifies the application through the **isDeviceCapabilityChanged** field in [AutoDeviceSwitchStatus](arkts-apis-camera-i.md#autodeviceswitchstatus13). The application needs to process the UX change by itself. For example, if the zoom range is different, the application needs to call [getZoomRatioRange](arkts-apis-camera-ZoomQuery.md#getzoomratiorange11) to obtain data and update the UX. Therefore, this class is more applicable to a simplified UX exchange scenario.
18
19## Modules to Import
20
21```ts
22import { camera } from '@kit.CameraKit';
23```
24
25## enableAutoDeviceSwitch<sup>13+</sup>
26
27enableAutoDeviceSwitch(enabled: boolean): void
28
29Enables or disables automatic camera switch. You can use [isAutoDeviceSwitchSupported](arkts-apis-camera-AutoDeviceSwitchQuery.md#isautodeviceswitchsupported13) to check whether the device supports automatic camera switch.
30
31> **NOTE**
32>
33> 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.
34
35**Atomic service API**: This API can be used in atomic services since API version 19.
36
37**System capability**: SystemCapability.Multimedia.Camera.Core
38
39**Parameters**
40
41| Name        | Type | Mandatory| Description |
42| ----------- |---------------------- |---| -------------------------- |
43| enabled | boolean  | Yes| Whether to enable automatic camera switch. **true** to enable, **false** otherwise.  |
44
45**Error codes**
46
47For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
48
49| ID  | Error Message                                                                                                                                      |
50|---------|------------------------------------------------------------------------------------------------------------------------------------------------|
51| 7400101 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameters verification failed. |
52| 7400102 | Operation not allowed.                                                                                                                         |
53| 7400103 | Session not config.                                                                                                                            |
54| 7400201 | Camera service fatal error.                                                                                                                    |
55
56**Example**
57
58```ts
59import { BusinessError } from '@kit.BasicServicesKit';
60
61function enableAutoDeviceSwitch(session: camera.PhotoSession, isEnable: boolean): void {
62  try {
63    session.enableAutoDeviceSwitch(isEnable);
64  } catch (error) {
65    let err = error as BusinessError;
66    console.error(`The enableAutoDeviceSwitch call failed, error code: ${err.code}`);
67  }
68}
69```
70