1# @ohos.multimodalAwareness.userStatus (User Status Awareness) 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 state awareness, empowers the system to perceive specific conditions of users, such as determining their age group. 10 11> **NOTE** 12> 13> The initial APIs of this module are supported since API version 20. Newly added APIs will be marked with a superscript to indicate their earliest API version. 14 15 16## Modules to Import 17 18```ts 19import { userStatus } from '@kit.MultimodalAwarenessKit'; 20``` 21 22## UserAgeGroup 23 24Enumerates the user age groups, for example, child or adult. 25 26**System capability**: SystemCapability.MultimodalAwareness.UserStatus 27 28| Name | Value | Description | 29| ------------------- | ---- | ---------------------- | 30| OTHERS | 0 | Adult.| 31| CHILD | 1 | Child.| 32 33## UserClassification 34 35Defines the user age group detection result. 36 37**System capability**: SystemCapability.MultimodalAwareness.UserStatus 38 39| Name | Type |Readable|Writable| Description | 40| ------------------- | ---- |----|----| ---------------------- | 41| ageGroup | [UserAgeGroup](#useragegroup) |Yes|No| User age group, for example, child or adult.| 42| confidence | float |Yes|No| Confidence of the detection result. The value is a floating point number ranging from 0 to 1. A larger value indicates a higher confidence.| 43 44 45## userStatus.on('userAgeGroupDetected') 46 47 on(type: 'userAgeGroupDetected', callback: Callback<UserClassification>): void; 48 49Enables the age group detection function. 50 51When the function is enabled, the application can recommend content based on the age group detection result. 52 53If the device does not support the function, error code 801 is returned. 54 55**System capability**: SystemCapability.MultimodalAwareness.UserStatus 56 57**Parameters** 58 59| Name | Type | Mandatory| Description | 60| -------- | -------------------------------- | ---- |------------------------------------------------------------ | 61| type | string | Yes | Event type. The value **userAgeGroupDetected** indicates the event of enabling age group detection.| 62| callback | Callback<[UserClassification](#userclassification)> | Yes | Callback used to return the detection result.| 63 64**Error codes** 65 66For details about the error codes, see [User Status Awareness Error Codes](errorcode-userStatus.md) and [Universal Error Codes](../errorcode-universal.md). 67 68| ID| Error Message | 69| -------- | ------------------------------------------------------------ | 70| 801 | Capability not supported. Function can not work correctly due to limited device capabilities. | 71| 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.| 72| 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. | 73 74**Example** 75 76```ts 77import { BusinessError } from '@kit.BasicServicesKit'; 78 79try { 80 userStatus.on('userAgeGroupDetected', (data: userStatus.UserClassification) => { 81 console.info('callback succeeded, ageGroup:' + data.ageGroup + ", confidence:" + data.confidence); 82 }); 83 console.info("on succeeded"); 84} catch (err) { 85 let error = err as BusinessError; 86 console.error("Failed on and err code is " + error.code); 87} 88``` 89 90 91 92## userStatus.off('userAgeGroupDetected') 93 94off(type: 'userAgeGroupDetected', callback?: Callback<UserClassification>): void; 95 96Disables the age group detection function. 97 98**System capability**: SystemCapability.MultimodalAwareness.UserStatus 99 100**Parameters** 101 102| Name | Type | Mandatory| Description | 103| -------- | -------------------------------- | ---- | ------------------------------------------------------------ | 104| type | string | Yes | Event type. The value **userAgeGroupDetected** indicates the event of enabling age group detection.| 105| callback | Callback<[UserClassification](#userclassification)> | No | Callback used to return the detection result.| 106 107**Error codes** 108 109For details about the error codes, see [User Status Awareness Error Codes](errorcode-userStatus.md) and [Universal Error Codes](../errorcode-universal.md). 110 111| ID| Error Message | 112| -------- | ------------------------------------------------------------ | 113| 801 | Capability not supported. Function can not work correctly due to limited device capabilities. | 114| 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. | 115| 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.| 116 117**Example** 118 119```ts 120import { BusinessError } from '@kit.BasicServicesKit'; 121 122try { 123 userStatus.off('userAgeGroupDetected'); 124 console.info("off succeeded"); 125} catch (err) { 126 let error = err as BusinessError; 127 console.error("Failed off and err code is " + error.code); 128} 129``` 130