• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# User Status Awareness Development
2<!--Kit: Multimodal Awareness Kit-->
3<!--Subsystem: MultimodalAwareness-->
4<!--Owner: @dilligencer-->
5<!--Designer: @zou_ye-->
6<!--Tester: @judan-->
7<!--Adviser: @hu-zhiqiong-->
8
9The UserStatus module, designed for user status awareness, empowers the system to perceive specific conditions of the operator, such as determining their age group.
10
11For details about the APIs, see the [userStatus API Reference](../../reference/apis-multimodalawareness-kit/js-apis-awareness-userStatus.md).
12
13## How to Develop
14### When to Use
15An application can invoke the UserStatus module when it needs to obtain the age group of users. This way, the application can determine, for example, whether the individual interacting with the device is a child or an adult.
16
17### Available APIs
18
19| API                                                      | Description                                  |
20| ------------------------------------------------------------ | -------------------------------------- |
21| on(type:'userAgeGroupDetected',callback:Callback&lt;UserClassification&gt;):void; | Enables the age group detection function. This API returns the result through a callback.|
22| off(type: 'userAgeGroupDetected', callback?: Callback&lt;UserClassification&gt;): void; | Disables the age group detection function.                  |
23
24### Constraints
25
26 - If the device does not support the age group detection function, error code 801 is returned.
27
28### Development Procedure
29
301. Import the related modules.
31
32   ```ts
33   import { userStatus } from '@kit.MultimodalAwarenessKit';
34   import { BusinessError } from '@kit.BasicServicesKit';
35   import { Callback } from '@ohos.base';
36   ```
37
382. Define the callback used to receive the age group detection result.
39
40   ```
41   let callback : Callback<userStatus.UserClassification> = (data : userStatus.UserClassification) => {
42     console.info('callback succeeded, ageGroup:' + data.ageGroup + ", confidence:" + data.confidence);
43   };
44   ```
45
463. Enable the age group detection function.
47
48   ```
49   try {
50      userStatus.on('userAgeGroupDetected', callback);
51      console.info("on succeeded");
52   } catch (err) {
53      let error = err as BusinessError;
54      console.error("Failed on and err code is " + error.code);
55   }
56   ```
57
584. Disable the age group detection function.
59
60   ```
61   try {
62      userStatus.off('userAgeGroupDetected');
63      console.info("off succeeded");
64   } catch (err) {
65      let error = err as BusinessError;
66      console.error("Failed off and err code is " + error.code);
67   }
68   ```
69