harmony 鸿蒙AppStateData

  • 2022-12-13
  • 浏览 (351)

AppStateData

定义应用状态信息,可以通过getForegroundApplications获取当前应用的相关信息。

说明:

本模块首批接口从API version 8 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

导入模块

import appManager from '@ohos.app.ability.appManager';

属性

系统能力:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core

系统API:本模块被标记为@systemapi,对三方应用隐藏

名称 类型 必填 说明
bundleName8+ string Bundle名称。
uid8+ number 应用程序的uid。
state8+ number 应用状态。
0:初始化状态,应用正在初始化
1:就绪状态,应用已初始化完毕
2:前台状态,应用位于前台
3:获焦状态。(预留状态,当前暂不支持)
4:后台状态,应用位于后台
5:退出状态,应用已退出

示例:

import appManager from '@ohos.app.ability.appManager';

function getForegroundAppInfos() {
    appManager.getForegroundApplications((error, data) => {
        if (error) {
            console.log(`getForegroundApplications failed, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}`);
            return;
        }
        for (let i = 0; i < data.length; i++) {
            let appStateData = data[i];
            console.log(`appStateData.bundleName: ${appStateData.bundleName}`);
            console.log(`appStateData.uid: ${appStateData.uid}`);
            console.log(`appStateData.state: ${appStateData.state}`);
        }
    });
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙接口

harmony 鸿蒙系统公共事件定义(待停用)

harmony 鸿蒙系统公共事件定义

harmony 鸿蒙开发说明

harmony 鸿蒙企业设备管理概述(仅对系统应用开放)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager模块)

harmony 鸿蒙@ohos.distributedBundle (分布式包管理)

harmony 鸿蒙@ohos.bundle (Bundle模块)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (企业设备管理扩展能力)

0  赞