openharmony 鸿蒙 js-apis-stationary

2025-06-12 浏览 (1)

@ohos.stationary (Device Status Awareness Framework)

The stationary module provides APIs to report the device status, including absolute still and relative still.

NOTE

The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.

This module does not support x86 emulators.

Modules to Import

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

ActivityResponse

Defines the response interface to receive the device status.

System capability: SystemCapability.Msdp.DeviceStatus.Stationary

NameTypeReadableWritableDescription
stateActivityStateYesNoNew device status.

ActivityType

type ActivityType = 'still'|'relativeStill'

Enumerates the device status types.

System capability: SystemCapability.Msdp.DeviceStatus.Stationary

TypeDescription
'still'Absolutely still.
'relativeStill'Relatively still.

ActivityEvent

Enumerates the device status events.

System capability: SystemCapability.Msdp.DeviceStatus.Stationary

NameValueDescription
ENTER1Event indicating entering device status.
EXIT2Event indicating exiting device status.
ENTER_EXIT3Event indicating entering and exiting device status.

ActivityState

Enumerates the device statuses.

System capability: SystemCapability.Msdp.DeviceStatus.Stationary

NameValueDescription
ENTER1Event indicating entering device status.
EXIT2Event indicating exiting device status.

stationary.on('still'|'relativeStill')

on(activity: ActivityType, event: ActivityEvent, reportLatencyNs: number, callback: Callback<ActivityResponse>): void

Subscribes to the device status.

System capability: SystemCapability.Msdp.DeviceStatus.Stationary

Parameters

NameTypeMandatoryDescription
activityActivityTypeYesDevice status type.
eventActivityEventYesEvent type.
reportLatencyNsnumberYesReport delay, in ns. The value ranges from 1000000000 to 3000000000.
callbackCallback<ActivityResponse>YesCallback used to receive reported data.

Example

let reportLatencyNs = 1000000000;
stationary.on('still', stationary.ActivityEvent.ENTER, reportLatencyNs, (data) => {
    console.log('data='+ JSON.stringify(data));
})

stationary.once('still'|'relativeStill')

once(activity: ActivityType, callback: Callback<ActivityResponse>): void

Obtains the device status.

System capability: SystemCapability.Msdp.DeviceStatus.Stationary

Parameters

NameTypeMandatoryDescription
activityActivityTypeYesDevice status type.
callbackCallback<ActivityResponse>YesCallback used to receive reported data.

Example

stationary.once('still', (data) => {
    console.log("data="+ JSON.stringify(data));
})

stationary.off('still'|'relativeStill')

off(activity: ActivityType, event: ActivityEvent, callback?: Callback<ActivityResponse>): void

Unsubscribes from the device status.

System capability: SystemCapability.Msdp.DeviceStatus.Stationary

Parameters

NameTypeMandatoryDescription
activityActivityTypeYesDevice status type.
eventActivityEventYesEvent type.
callbackCallback<ActivityResponse>NoCallback used to receive reported data. If no value or undefined is passed, all callbacks associated with the specified event in the process will be unregistered.

Example

stationary.off('still', stationary.ActivityEvent.ENTER);

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Multimodal Awareness Kit

harmony 鸿蒙Device Status Awareness Error Codes

harmony 鸿蒙Metadata Binding Error Codes

harmony 鸿蒙Motion Awareness Error Codes

harmony 鸿蒙@ohos.multimodalAwareness.deviceStatus (Device Status Awareness)

harmony 鸿蒙@ohos.multimodalAwareness.metadataBinding (Metadata Binding)

harmony 鸿蒙@ohos.multimodalAwareness.metadataBinding (Metadata Binding)

harmony 鸿蒙@ohos.multimodalawareness.motion (Motion Awareness)

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