• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.multimodalAwareness.userStatus (用户状态感知)
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 20开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
14
15
16## 导入模块
17
18```ts
19import { userStatus } from '@kit.MultimodalAwarenessKit';
20```
21
22## UserAgeGroup
23
24表示用户具体的年龄分类群组,例如,儿童或成年人。
25
26**系统能力**:SystemCapability.MultimodalAwareness.UserStatus
27
28| 名称                | 值  | 说明                   |
29| ------------------- | ---- | ---------------------- |
30| OTHERS  | 0    | 表示是成年人操作。 |
31| CHILD  | 1    | 表示是儿童操作。 |
32
33## UserClassification
34
35表示用户年龄群组分类检测结果。
36
37**系统能力**:SystemCapability.MultimodalAwareness.UserStatus
38
39| 名称                | 类型   |只读|可选| 说明                   |
40| ------------------- | ---- |----|----| ---------------------- |
41| ageGroup  | [UserAgeGroup](#useragegroup)   |否|否| 表示具体的年龄群组(例如,儿童、成人)。 |
42| confidence  | float    |否|否| 表示年龄群组检测结果的置信度,取值范围为0~1的浮点数,数值越大代表置信度越高。 |
43
44
45## userStatus.on('userAgeGroupDetected')
46
47 on(type: 'userAgeGroupDetected', callback: Callback&lt;UserClassification&gt;): void
48
49订阅年龄群组检测功能。
50
51订阅成功后,可以获取用户年龄群组的分类结果,应用可根据此结果做相应的内容推荐。
52
53**系统能力**:SystemCapability.MultimodalAwareness.UserStatus
54
55**设备行为差异**:该接口在Phone中可正常调用,在其他设备类型中返回801错误码。
56
57> **说明:**
58>
59> 该接口仅在部分Phone中支持使用,当Phone设备不支持时返回801错误码。
60
61**参数**:
62
63| 参数名   | 类型                             | 必填 | 说明                                                         |
64| -------- | -------------------------------- | ---- |------------------------------------------------------------ |
65| type     | string                           | 是   | 事件类型。type为“userAgeGroupDetected”,表示年龄群组检测功能。 |
66| callback | Callback&lt;[UserClassification](#userclassification)&gt; | 是   | 回调函数,返回检测结果。|
67
68**错误码**:
69
70以下错误码的详细介绍请参见[用户状态感知错误码](errorcode-userStatus.md)和[通用错误码](../errorcode-universal.md)。
71
72| 错误码ID | 错误信息                                                     |
73| -------- | ------------------------------------------------------------ |
74| 801      | Capability not supported. Function can not work correctly due to limited device capabilities. |
75| 33900001 | Service exception. Possible causes: <br>1. System error, such as a null pointer and container-related exception. <br>2. Node-API invocation exception, such as invalid Node-API status.|
76| 33900002 | Subscription failed. Possible causes: <br>1. Callback registration failed. <br>2. Failed to bind the native object to the JS wrapper. <br>3. Node-API invocation exception, such as invalid Node-API status. <br>4. IPC request exception. |
77
78**示例**:
79
80```ts
81import { BusinessError } from '@kit.BasicServicesKit';
82
83try {
84    userStatus.on('userAgeGroupDetected', (data: userStatus.UserClassification) => {
85        console.info('callback succeeded, ageGroup:' + data.ageGroup + ", confidence:" + data.confidence);
86    });
87    console.info("on succeeded");
88} catch (err) {
89    let error = err as BusinessError;
90    console.error("Failed on and err code is " + error.code);
91}
92```
93
94
95
96## userStatus.off('userAgeGroupDetected')
97
98off(type: 'userAgeGroupDetected', callback?: Callback&lt;UserClassification&gt;): void
99
100取消订阅年龄群组检测功能。
101
102**系统能力**:SystemCapability.MultimodalAwareness.UserStatus
103
104**设备行为差异**:该接口在Phone中可正常调用,在其他设备类型中返回33900003错误码。
105
106> **说明:**
107>
108> 该接口仅在部分Phone中支持使用,当Phone设备不支持时返回33900003错误码。
109
110**参数**:
111
112| 参数名   | 类型                             | 必填 | 说明                                                         |
113| -------- | -------------------------------- | ---- | ------------------------------------------------------------ |
114| type     | string                           | 是   | 事件类型。type为“userAgeGroupDetected”,表示年龄群组检测功能。|
115| callback | Callback&lt;[UserClassification](#userclassification)&gt; | 否   | 回调函数,返回检测结果。 |
116
117**错误码**:
118
119以下错误码的详细介绍请参见[用户状态感知错误码](errorcode-userStatus.md)和[通用错误码](../errorcode-universal.md)。
120
121| 错误码ID | 错误信息                                                     |
122| -------- | ------------------------------------------------------------ |
123| 801      | Capability not supported. Function can not work correctly due to limited device capabilities. |
124| 33900001 | Service exception. Possible causes: <br>1. System error, such as a null pointer and container-related exception. <br>2. Node-API invocation exception, such as invalid Node-API status. |
125| 33900003 | Unsubscription failed. Possible causes: <br>1. Callback failure. <br>2. Node-API invocation exception, such as invalid Node-API status. <br>3. IPC request exception.|
126
127**示例**:
128
129```ts
130import { BusinessError } from '@kit.BasicServicesKit';
131
132try {
133    userStatus.off('userAgeGroupDetected');
134    console.info("off succeeded");
135} catch (err) {
136    let error = err as BusinessError;
137    console.error("Failed off and err code is " + error.code);
138}
139```
140