js-apis-inner-application-extensionRunningInfo.md 2.6 KB
Newer Older
W
wusongqing 已提交
1 2
# ExtensionRunningInfo

3
The **ExtensionRunningInfo** module encapsulates ExtensionAbility running information, which can be obtained through [getExtensionRunningInfos](js-apis-app-ability-abilityManager.md#getextensionrunninginfos).
4

W
wusongqing 已提交
5 6
> **NOTE**
> 
7 8
>  - 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 is marked as @systemapi and not visible to third-party applications.
W
wusongqing 已提交
9 10 11

## Usage

12
Import the **abilityManager** module and obtain the ExtensionAbility running information by calling the method in the **abilityManager** module.
W
wusongqing 已提交
13

14
## Attributes
W
wusongqing 已提交
15

W
wusongqing 已提交
16 17
**System capability**: SystemCapability.Ability.AbilityRuntime.Core

W
wusongqing 已提交
18
| Name| Type| Readable| Writable| Description|
W
wusongqing 已提交
19
| -------- | -------- | -------- | -------- | -------- |
20
| extension | [ElementName](js-apis-bundleManager-elementName.md) | Yes| No| ExtensionAbility information.|
W
wusongqing 已提交
21
| pid | number | Yes| No| Process ID.|
22
| uid | number | Yes| No| UID of the application.|
W
wusongqing 已提交
23
| processName | string | Yes| No| Process name.|
24
| startTime | number | Yes| No| Timestamp when the ExtensionAbility is started.|
W
wusongqing 已提交
25
| clientPackage | Array<String> | Yes| No| Names of all packages in the process.|
26
| type | [ExtensionAbilityType](js-apis-bundleManager.md#extensionabilitytype) | Yes| No| ExtensionAbility type.|
27 28 29

**Example**
```ts
30
import abilityManager from '@ohos.app.ability.abilityManager';
31

32
let upperLimit = 1;
33 34 35
function getExtensionInfos() {
    abilityManager.getExtensionRunningInfos(upperLimit, (error, data) => {
        if (error && error.code) {
G
Gloria 已提交
36
            console.error('getForegroundApplications failed, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}');
37 38 39 40 41
            return;
        }

        for (let i = 0; i < data.length; i++) {
            let extensionRunningInfo = data[i];
42 43 44 45 46 47 48
            console.log('extensionRunningInfo.extension: ${JSON.stringify(extensionRunningInfo.extension)}');
            console.log('extensionRunningInfo.pid: ${JSON.stringify(extensionRunningInfo.pid)}');
            console.log('extensionRunningInfo.uid: ${JSON.stringify(extensionRunningInfo.uid)}');
            console.log('extensionRunningInfo.processName: ${JSON.stringify(extensionRunningInfo.processName)}');
            console.log('extensionRunningInfo.startTime: ${JSON.stringify(extensionRunningInfo.startTime)}');
            console.log('extensionRunningInfo.clientPackage: ${JSON.stringify(extensionRunningInfo.clientPackage)}');
            console.log('extensionRunningInfo.type: ${JSON.stringify(extensionRunningInfo.type)}');
49 50 51
        }
    });
}
52
```