1# @ohos.multimodalAwareness.deviceStatus(设备状态感知) 2<!--Kit: Multimodal Awareness Kit--> 3<!--Subsystem: MultimodalAwareness--> 4<!--Owner: @dilligencer--> 5<!--Designer: @zou_ye--> 6<!--Tester: @judan--> 7<!--Adviser: @hu-zhiqiong--> 8 9本模块提供对设备状态的感知能力。 10 11> **说明:** 12> 13> 本模块首批接口从API version 18开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 14 15## 导入模块 16 17 ```ts 18 import { deviceStatus } from '@kit.MultimodalAwarenessKit'; 19 ``` 20 21## SteadyStandingStatus 22 23设备静止姿态感知状态(支架态)。 24 25设备进入支架态指设备静止,且屏幕与水平面角度处于45度-135度。折叠屏手机需处于折叠状态或者完全展开状态。 26 27**系统能力**:SystemCapability.MultimodalAwareness.DeviceStatus 28 29| 名称 | 值 | 说明 | 30| ------------------- | ---- | ---------------------- | 31| STATUS_EXIT | 0 | 表示设备退出支架态。 | 32| STATUS_ENTER | 1 | 表示设备进入支架态。 | 33 34## deviceStatus.on('steadyStandingDetect') 35 36 on(type: 'steadyStandingDetect', callback: Callback<SteadyStandingStatus>): void 37 38订阅设备静止姿态感知(支架态)事件。 39 40**系统能力**:SystemCapability.MultimodalAwareness.DeviceStatus 41 42**参数**: 43 44| 参数名 | 类型 | 必填 | 说明 | 45| -------- | -------------------------------- | ---- | ------------------------------------------------------------ | 46| type | string | 是 | 事件类型。type为“steadyStandingDetect”,表示设备静止姿态(支架态)感知。 | 47| callback | Callback<[SteadyStandingStatus](#steadystandingstatus)> | 是 | 回调函数,返回设备静止姿态感知(支架态)状态信息。| 48 49**错误码**: 50 51以下错误码的详细介绍请参见[设备状态感知错误码](errorcode-deviceStatus.md)和[通用错误码](../errorcode-universal.md)。 52 53| 错误码ID | 错误信息 | 54| -------- | ------------------------------------------------------------ | 55| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 56| 801 | Capability not supported. Function can not work correctly due to limited device capabilities. | 57| 32500001 | Service exception. | 58| 32500002 | Subscription failed. | 59 60**示例**: 61 62 ```ts 63 try { 64 deviceStatus.on('steadyStandingDetect', (data:deviceStatus.SteadyStandingStatus) => { 65 console.info('succeed to get status, now status = ' + data); 66 }); 67 } catch (err) { 68 console.error('on failed, err = ' + err); 69 } 70 ``` 71 72## deviceStatus.off('steadyStandingDetect') 73 74off(type: 'steadyStandingDetect', callback?: Callback<SteadyStandingStatus>): void 75 76取消订阅设备静止姿态感知(支架态)事件。 77 78**系统能力**:SystemCapability.MultimodalAwareness.DeviceStatus 79 80**参数**: 81 82| 参数名 | 类型 | 必填 | 说明 | 83| -------- | -------------------------------- | ---- | ------------------------------------------------------------ | 84| type | string | 是 | 事件类型。type为“steadyStandingDetect”,表示设备静止姿态(支架态)感知。 | 85| callback | Callback<[SteadyStandingStatus](#steadystandingstatus)> | 否 | 回调函数,返回设备静止姿态感知(支架态)状态信息。| 86 87**错误码**: 88 89以下错误码的详细介绍请参见[设备状态感知错误码](errorcode-deviceStatus.md)和[通用错误码](../errorcode-universal.md)。 90 91| 错误码ID | 错误信息 | 92| -------- | ------------------------------------------------------------ | 93| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. | 94| 801 | Capability not supported. Function can not work correctly due to limited device capabilities. | 95| 32500001 | Service exception. | 96| 32500003 | Unsubscription failed. | 97 98**示例**: 99 100示例一:取消订阅该客户端订阅设备静止姿态感知(支架态)事件的所有回调。 101 102 ```ts 103 try { 104 deviceStatus.off('steadyStandingDetect'); 105 } catch (err) { 106 console.error('off failed, err = ' + err); 107 } 108 ``` 109 110示例二:取消订阅该客户端订阅设备静止姿态感知(支架态)事件的特定回调。 111 112 ```ts 113 import { Callback } from '@ohos.base'; 114 // 定义callback变量 115 let callback : Callback<deviceStatus.SteadyStandingStatus> = (data : deviceStatus. SteadyStandingStatus) => { 116 console.info('succeed to get status, now status = ' + data); 117 }; 118 // 以callback为回调函数,订阅设备静止姿态感知(支架态)事件 119 try { 120 deviceStatus.on('steadyStandingDetect', callback); 121 } catch (err) { 122 console.error('on failed, err = ' + err); 123 } 124 // 取消该客户端订阅设备静止姿态感知(支架态)事件的特定回调函数 125 try { 126 deviceStatus.off('steadyStandingDetect', callback); 127 } catch (err) { 128 console.error('off failed, err = ' + err); 129 } 130 ```