openharmony 鸿蒙 js-apis-awareness-userStatus

2026-08-25 浏览 (1)

@ohos.multimodalAwareness.userStatus (用户状态感知)

本模块提供用户状态感知能力,包括年龄群组检测等功能。

说明:

本模块首批接口从API version 20开始支持。从API version 24开始废弃,无替代接口。

导入模块

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

UserAgeGroup(deprecated)

表示用户具体的年龄分类群组,例如,儿童或成年人。

系统能力:SystemCapability.MultimodalAwareness.UserStatus

名称说明
OTHERS0表示是成年人操作。
CHILD1表示是儿童操作。

UserClassification(deprecated)

表示用户年龄群组分类检测结果。

系统能力:SystemCapability.MultimodalAwareness.UserStatus

名称类型只读可选说明
ageGroupUserAgeGroup表示具体的年龄群组(例如,儿童、成人)。
confidencefloat表示年龄群组检测结果的置信度,取值范围[0,1]的浮点数,数值越大代表置信度越高。

userStatus.on('userAgeGroupDetected')(deprecated)

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

订阅年龄群组检测功能。

订阅成功后,可以获取用户年龄群组的分类结果,应用可根据此结果做相应的内容推荐。

系统能力:SystemCapability.MultimodalAwareness.UserStatus

设备行为差异:该接口在Phone中可正常调用,在其他设备类型中返回801错误码。

说明:

该接口仅在部分Phone中支持使用,当Phone设备不支持时返回801错误码。

参数

参数名类型必填说明
typestring事件类型。type为“userAgeGroupDetected”,表示年龄群组检测功能。
callbackCallback<UserClassification>回调函数,返回检测结果。

错误码

以下错误码的详细介绍请参见用户状态感知错误码通用错误码

错误码ID错误信息
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.

示例

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

取消订阅年龄群组检测功能。

系统能力:SystemCapability.MultimodalAwareness.UserStatus

设备行为差异:该接口在Phone中可正常调用,在其他设备类型中返回33900003错误码。

说明:

该接口仅在部分Phone中支持使用,当Phone设备不支持时返回33900003错误码。

参数

参数名类型必填说明
typestring事件类型。type为“userAgeGroupDetected”,表示年龄群组检测功能。
callbackCallback<UserClassification>回调函数,返回检测结果。

错误码

以下错误码的详细介绍请参见用户状态感知错误码通用错误码

错误码ID错误信息
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.

示例

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-CN

openharmony 鸿蒙 errorcode-userStatus

openharmony 鸿蒙 errorcode-deviceStatus

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

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