openharmony 鸿蒙 js-apis-awareness-userStatus

2026-08-25 浏览 (1)

@ohos.multimodalAwareness.userStatus (User Status Awareness)

The UserStatus module, designed for user state awareness, empowers the system to perceive specific conditions of users, such as determining their age group.

NOTE

The initial APIs of this module are supported since API version 20. This API is deprecated since API version 24. No substitute API is provided.

Modules to Import

import { userStatus } from '@kit.MultimodalAwarenessKit';

UserAgeGroup(deprecated)

Enumerates the user age groups, for example, child or adult.

System capability: SystemCapability.MultimodalAwareness.UserStatus

NameValueDescription
OTHERS0Adult.
CHILD1Child.

UserClassification(deprecated)

Defines the user age group detection result.

System capability: SystemCapability.MultimodalAwareness.UserStatus

NameTypeRead-OnlyOptionalDescription
ageGroupUserAgeGroupNoYesUser age group, for example, child or adult.
confidencefloatNoYesConfidence of the detection result. The value is a floating point number ranging from 0 to 1. A larger value indicates a higher confidence.

userStatus.on('userAgeGroupDetected')(deprecated)

on(type: 'userAgeGroupDetected', callback: Callback<UserClassification>): void

Enables the age group detection function.

When the function is enabled, the application can recommend content based on the age group detection result.

System capability: SystemCapability.MultimodalAwareness.UserStatus

Device behavior differences: This API can be called on phones. If it is called on other devices, error code 801 is returned.

NOTE

This API is supported only on some phones. Error code 801 is returned if it is called on unsupported phones.

Parameters

NameTypeMandatoryDescription
typestringYesEvent type. The value userAgeGroupDetected indicates the event of enabling age group detection.
callbackCallback<UserClassification>YesCallback used to return the detection result.

Error codes

For details about the error codes, see User Status Awareness Error Codes and Universal Error Codes.

IDError Message
801Capability not supported. Function can not work correctly due to limited device capabilities.
33900001Service exception. Possible causes:
1. System error, such as a null pointer and container-related exception.
2. Node-API invocation exception, such as invalid Node-API status.
33900002Subscription failed. Possible causes:
1. Callback registration failed.
2. Failed to bind the native object to the JS wrapper.
3. Node-API invocation exception, such as invalid Node-API status.
4. IPC request exception.

Example

import { BusinessError } from '@kit.BasicServicesKit';

try {
    userStatus.on('userAgeGroupDetected', (data: userStatus.UserClassification) => {
        console.info('callback succeeded, ageGroup:' + data.ageGroup + ", confidence:" + data.confidence);
    });
    console.info("on succeeded");
} catch (err) {
    let error = err as BusinessError;
    console.error("Failed on and err code is " + error.code);
}

userStatus.off('userAgeGroupDetected')(deprecated)

off(type: 'userAgeGroupDetected', callback?: Callback<UserClassification>): void

Disables the age group detection function.

System capability: SystemCapability.MultimodalAwareness.UserStatus

Device behavior differences: This API can be called on phones. If it is called on other devices, error code 33900003 is returned.

NOTE

This API is supported only on some phones. Error code 33900003 is returned if it is called on unsupported phones.

Parameters

NameTypeMandatoryDescription
typestringYesEvent type. The value userAgeGroupDetected indicates the event of enabling age group detection.
callbackCallback<UserClassification>NoCallback used to return the detection result.

Error codes

For details about the error codes, see User Status Awareness Error Codes and Universal Error Codes.

IDError Message
801Capability not supported. Function can not work correctly due to limited device capabilities.
33900001Service exception. Possible causes:
1. System error, such as a null pointer and container-related exception.
2. Node-API invocation exception, such as invalid Node-API status.
33900003Unsubscription failed. Possible causes:
1. Callback failure.
2. Node-API invocation exception, such as invalid Node-API status.
3. IPC request exception.

Example

import { BusinessError } from '@kit.BasicServicesKit';

try {
    userStatus.off('userAgeGroupDetected');
    console.info("off succeeded");
} catch (err) {
    let error = err as BusinessError;
    console.error("Failed off and err code is " + error.code);
}

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 errorcode-onScreen

openharmony 鸿蒙 js-apis-awareness-metadataBinding-sys

openharmony 鸿蒙 errorcode-metadataBinding

openharmony 鸿蒙 js-apis-awareness-deviceStatus-sys

openharmony 鸿蒙 js-apis-awareness-motion

openharmony 鸿蒙 js-apis-awareness-metadataBinding

openharmony 鸿蒙 Readme-EN

openharmony 鸿蒙 errorcode-userStatus

openharmony 鸿蒙 errorcode-deviceStatus

openharmony 鸿蒙 js-apis-awareness-onScreen-sys

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/CMxnarTI