• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# AppStateData
2
3The **AppStateData** module defines the application state data, which can be obtained through [getForegroundApplications](js-apis-app-ability-appManager.md#appmanagergetforegroundapplications).
4
5> **NOTE**
6>
7> 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.
8
9## Modules to Import
10
11```ts
12import appManager from '@ohos.app.ability.appManager';
13```
14
15## Attributes
16
17**System capability**: SystemCapability.Ability.AbilityRuntime.Core
18
19**System API**: This module is marked as @systemapi and not visible to third-party applications.
20
21| Name                     | Type  | Mandatory | Description      |
22| ------------------------- | ------ | ---- | --------- |
23| bundleName<sup>8+</sup>   | string | No  | Bundle name.|
24| uid<sup>8+</sup>          | number | No  | UID of the application.  |
25| state<sup>8+</sup>        | number | No  | Application state.<br>**0**: The application is being initialized.<br>**1**: The application has been initialized and is ready.<br>**2**: The application is running in the foreground.<br>**3**: The application is having the focus. (This state is reserved.)<br>**4**: The application is running in the background.<br>**5**: The application has exited.|
26| isSplitScreenMode<sup>11+</sup> | boolean | No| Whether the application is in split-screen mode.<br>**true**: The application is in split-screen mode.<br>**false**: The application is not in split-screen mode.|
27| isFloatingWindowMode<sup>11+</sup> | boolean | No| Whether the application is in floating window mode.<br>**true**: The application is in floating window mode.<br>**false**: The application is not in floating window mode.|
28
29**Example**
30
31```ts
32import appManager from '@ohos.app.ability.appManager';
33
34function getForegroundAppInfos() {
35    appManager.getForegroundApplications((error, data) => {
36        if (error) {
37            console.log(`getForegroundApplications failed, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}`);
38            return;
39        }
40        for (let i = 0; i < data.length; i++) {
41            let appStateData = data[i];
42            console.log(`appStateData.bundleName: ${appStateData.bundleName}`);
43            console.log(`appStateData.uid: ${appStateData.uid}`);
44            console.log(`appStateData.state: ${appStateData.state}`);
45            console.log(`appStateData.isSplitScreenMode: ${appStateData.isSplitScreenMode}`);
46            console.log(`appStateData.isFloatingWindowMode: ${appStateData.isFloatingWindowMode}`);
47        }
48    });
49}
50```
51