harmony 鸿蒙Device Status Awareness Development

  • 2025-06-06
  • 浏览 (3)

Device Status Awareness Development

The DeviceStatus module provides device status awareness capabilities such as obtaining the steady standing state (that is, stand mode).

For details about the APIs, see the API Reference.

Concepts

Understanding the following concepts would be helpful for you in device status awareness development:

  • Stand moe

    A device enters stand mode when it is stationary, and its screen is at an angle between 45 and 135 degrees relative to the horizontal plane. For foldable smartphones, the device must be in a folded state or fully unfolded state.

How to Develop

Overview

During development, subscribe to steady standing state change events and obtain the current state through the callback passed in during subscription.

Constraints

The device must support the accelerometer and specific chips.

APIs

API Description
on(type: ‘steadyStandingDetect’, callback: Callback<SteadyStandingStatus>): void; Subscribes to steady standing state change events. This API returns the result through a callback.
off(type: ‘steadyStandingDetect’, callback: Callback<SteadyStandingStatus>): void; Unsubscribes from steady standing state change events. This API returns the result through a callback.

Development Procedure

  1. Import the deviceStatus module.
  import { deviceStatus } from '@kit.MultimodalAwarenessKit';
  1. Subscribe to steady standing state change events.
  try {
    deviceStatus.on('steadyStandingDetect', (data:deviceStatus.SteadyStandingStatus) => {
      console.info('now status = ' + data);
    });
  } catch (err) {
    console.info('on failed, err = ' + err);
  }
  1. Unsubscribe from all callbacks of steady standing state change events.
  try {
    deviceStatus.off('steadyStandingDetect');
  } catch (err) {
    console.info('off failed, err = ' + err);
  }
  1. Unsubscribe from the specific callback of steady standing state change events.
  import { Callback } from '@ohos.base';
  // Define the callback variable.
  let callback : Callback<deviceStatus.SteadyStandingStatus> = (data : deviceStatus.SteadyStandingStatus) => {
    console.info('now status = ' + data);
  };
  // Subscribe to a specific callback of steady standing state change events.
  try {
    deviceStatus.on('steadyStandingDetect', callback);
  } catch (err) {
    console.info('on failed, err = ' + err);
  }
  // Unsubscribe from the specific callback of steady standing state change events.
  try {
    deviceStatus.off('steadyStandingDetect', callback);
  } catch (err) {
    console.info('off failed, err = ' + err);
  }

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Multimodal Awareness Kit

harmony 鸿蒙Motion Awareness Development

harmony 鸿蒙Introduction to Multimodal Awareness Kit

harmony 鸿蒙Stationary Development

0  赞