可帮助开发者学习在HarmonyOS不同应用包(HAP、HAR、HSP)环境中获取应用上下文实例。核心功能包括获取UIAbilityContext、ApplicationContext和WindowStage实例,实现对界面、应用状态及窗口管理的控制。
| Files | Last commit | Last update |
|---|---|---|
| 1 year ago | ||
| 11 months ago | ||
| 1 year ago | ||
| 1 year ago | ||
| 1 year ago | ||
| 1 year ago | ||
| 1 year ago | ||
| 5 months ago | ||
| 5 months ago | ||
| 1 year ago | ||
| 1 year ago | ||
| 1 year ago |
Obtaining the Application Context
Overview
This sample describes how to obtain the UIAbilityContext, ApplicationContext, and WindowStage instances in the HAP, HAR, and HSP environments.
Preview
| UIAbilityContext | ApplicationContext | WindowStage |
|---|---|---|
![]() |
![]() |
![]() |
How to Use
- Click the "Get UIAbilityContext" button on the home page to navigate to the sub-page. Click the buttons on the page in sequence, and the AbilityName values obtained in different scenarios will be displayed in the text box.
- Click the "Get ApplicationContext" button on the home page to navigate to the sub-page. Click the buttons on the page in sequence, and the filesDir values obtained through the Application instance in different scenarios will be displayed in the text box.
- Click the "Get WindowStage" button on the home page to navigate to the sub-page. Click the buttons on the page in sequence, and the window width and height values obtained in different scenarios will be displayed in the text box.
Project Directory
├──entry
│ ├──src/main/ets/
│ │ ├──common
│ │ │ └──Logger.ets // Logger
│ │ ├──entryability
│ │ │ └──EntryAbility.ets // Entry ability
│ │ ├──entrybackupability
│ │ │ └──EntryBackupAbility.ets // Data backup and restoration
│ │ ├──pages
│ │ │ ├──GetApplicationContextDemo.ets // Obtaining the ApplicationContext code demo
│ │ │ ├──GetUIAbilityContextDemo.ets // Obtaining the UIAbilityContext code demo
│ │ │ ├──GetWindowStageDemo.ets // Obtaining the WindowStage code demo
│ │ │ └──Index.ets // App entry
│ │ └──workers
│ │ └──MyWorker.ets // Worker child thread
│ └──src/main/resources // Static resources
├──har // HAR module
│ ├──Index.ets // Entry file, which exposes the module methods
│ ├──src/main/ets/components/mainpage
│ │ └──MainPage.ets // Main page
│ └──src/main/resources // Static resources of the app
└──hsp // HSP module
├──Index.ets // Entry file, which exposes the module methods
├──src/main/ets/components/mainpage
│ └──Index.ets // Home page
└──src/main/resources // Static resources of the app
Permissions
N/A
Dependencies
N/A
Constraints
- The sample is only supported on Huawei phones with standard systems.
- The HarmonyOS version must be HarmonyOS 5.0.5 Release or later.
- The DevEco Studio version must be DevEco Studio 5.0.5 Release or later.
- The HarmonyOS SDK version must be HarmonyOS 5.0.5 Release SDK or later.
Introduction
可帮助开发者学习在HarmonyOS不同应用包(HAP、HAR、HSP)环境中获取应用上下文实例。核心功能包括获取UIAbilityContext、ApplicationContext和WindowStage实例,实现对界面、应用状态及窗口管理的控制。
Customize your domain

