1e41f4b71Sopenharmony_ci # AppStateData (系统接口) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci定义应用状态信息,可以通过[getForegroundApplications](js-apis-app-ability-appManager-sys.md#appmanagergetforegroundapplications)获取当前应用的相关信息。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **说明:** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 8 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8e41f4b71Sopenharmony_ci> 本模块接口为系统接口。 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## 导入模块 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci```ts 13e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 14e41f4b71Sopenharmony_ci``` 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci## 属性 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci**系统API**:本模块被标记为@systemapi,对三方应用隐藏 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 23e41f4b71Sopenharmony_ci| ------------------------- | ------ | ---- | --------- | 24e41f4b71Sopenharmony_ci| bundleName<sup>8+</sup> | string | 否 | Bundle名称。 | 25e41f4b71Sopenharmony_ci| uid<sup>8+</sup> | number | 否 | 应用程序的uid。 | 26e41f4b71Sopenharmony_ci| state<sup>8+</sup> | number | 否 | 应用状态。<br>0:初始化状态,应用正在初始化<br>1:就绪状态,应用已初始化完毕<br>2:前台状态,应用位于前台<br>3:获焦状态。(预留状态,当前暂不支持)<br>4:后台状态,应用位于后台<br>5:退出状态,应用已退出 | 27e41f4b71Sopenharmony_ci| isSplitScreenMode<sup>11+</sup> | boolean | 否 | 判断应用是否进入分屏模式。<br>true:应用处于分屏模式。<br>false:应用不处于分屏模式。 | 28e41f4b71Sopenharmony_ci| isFloatingWindowMode<sup>11+</sup> | boolean | 否 | 判断应用是否进入悬浮窗模式。<br>true:应用处于浮窗模式。<br>false:应用不处于浮窗模式。 | 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci**示例:** 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci```ts 33e41f4b71Sopenharmony_ciimport { appManager } from '@kit.AbilityKit'; 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_cifunction getForegroundAppInfos() { 36e41f4b71Sopenharmony_ci appManager.getForegroundApplications((error, data) => { 37e41f4b71Sopenharmony_ci if (error) { 38e41f4b71Sopenharmony_ci console.log(`getForegroundApplications failed, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}`); 39e41f4b71Sopenharmony_ci return; 40e41f4b71Sopenharmony_ci } 41e41f4b71Sopenharmony_ci for (let i = 0; i < data.length; i++) { 42e41f4b71Sopenharmony_ci let appStateData = data[i]; 43e41f4b71Sopenharmony_ci console.log(`appStateData.bundleName: ${appStateData.bundleName}`); 44e41f4b71Sopenharmony_ci console.log(`appStateData.uid: ${appStateData.uid}`); 45e41f4b71Sopenharmony_ci console.log(`appStateData.state: ${appStateData.state}`); 46e41f4b71Sopenharmony_ci console.log(`appStateData.isSplitScreenMode: ${appStateData.isSplitScreenMode}`); 47e41f4b71Sopenharmony_ci console.log(`appStateData.isFloatingWindowMode: ${appStateData.isFloatingWindowMode}`); 48e41f4b71Sopenharmony_ci } 49e41f4b71Sopenharmony_ci }); 50e41f4b71Sopenharmony_ci} 51e41f4b71Sopenharmony_ci``` 52