harmony 鸿蒙@ohos.app.ability.abilityManager (AbilityManager)

  • 2025-06-12
  • 浏览 (4)

@ohos.app.ability.abilityManager (AbilityManager)

The AbilityManager module provides APIs for obtaining ability information and running status information.

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.

Modules to Import

import { abilityManager } from '@kit.AbilityKit';

AbilityState

Enumerates the ability states. This enum can be used together with AbilityRunningInfo to return the ability state.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Name Value Description
INITIAL 0 The ability is in the initial state.
FOCUS 2 The ability has the focus.
FOREGROUND 9 The ability is in the foreground state.
BACKGROUND 10 The ability is in the background state.
FOREGROUNDING 11 The ability is in the state of being switched to the foreground.
BACKGROUNDING 12 The ability is in the state of being switched to the background.

abilityManager.getAbilityRunningInfos

getAbilityRunningInfos(): Promise<Array<AbilityRunningInfo>>

Obtains the UIAbility running information. This API uses a promise to return the result.

Required permissions: ohos.permission.GET_RUNNING_INFO

System capability: SystemCapability.Ability.AbilityRuntime.Core

Return value

Type Description
Promise<Array<AbilityRunningInfo>> Promise used to return the API call result and the UIAbility running information. You can perform error handling or custom processing in it.

Error codes

For details about the error codes, see Ability Error Codes.

ID Error Message
16000050 Internal error.

Example

import { abilityManager } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';

try {
  abilityManager.getAbilityRunningInfos()
    .then((data: abilityManager.AbilityRunningInfo[]) => {
      console.log(`getAbilityRunningInfos success, data: ${JSON.stringify(data)}`);
    })
    .catch((error: BusinessError) => {
      console.error(`getAbilityRunningInfos fail, error code: ${JSON.stringify(error.code)}, error msg: ${JSON.stringify(error.message)}`);
    })
} catch (e) {
  let code = (e as BusinessError).code;
  let msg = (e as BusinessError).message;
  console.error(`getAbilityRunningInfos fail, error code: ${JSON.stringify(code)}, error msg: ${JSON.stringify(msg)}`);
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Ability Kit

harmony 鸿蒙AbilityAccessControl

harmony 鸿蒙AbilityBase

harmony 鸿蒙AbilityBase_Element

harmony 鸿蒙AbilityRuntime

harmony 鸿蒙bundle

harmony 鸿蒙OH_NativeBundle_ApplicationInfo

harmony 鸿蒙OH_NativeBundle_ElementName

harmony 鸿蒙ability_access_control.h

harmony 鸿蒙ability_base_common.h

0  赞