harmony 鸿蒙AppStateData

  • 2022-12-22
  • 浏览 (376)

AppStateData

The AppStateData module defines the application state data, which can be obtained through getForegroundApplications.

NOTE

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

Modules to Import

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

Attributes

System capability: SystemCapability.Ability.AbilityRuntime.Core

System API: This module is marked as @systemapi and not visible to third-party applications.

Name Type Mandatory Description
bundleName8+ string No Bundle name.
uid8+ number No UID of the application.
state8+ number No Application state.
0: The application is being initialized.
1: The application has been initialized and is ready.
2: The application is running in the foreground.
3: The application is having the focus. (This state is reserved.)
4: The application is running in the background.
5: The application has exited.

Example

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 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

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

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

0  赞