Obtaining UIAbility Context
In HarmonyOS development, you can retrieve the current ability's context directly within EntryAbility, or obtain the UIAbility instance information from any Page component.
Configuring Want Parameters
The Want object contains several configuration parameters. The two essential parameters are:
bundleName: The target application's bundle identifierabilityName: The target UIAbility's name
Initiating Navigation
Use context.startAbility(want) to navigate to another UIAbility. The implementation follows:
import common from '@ohos.app.ability.common';
@Component
struct MainPage {
build() {
Button('Navigate')
.onClick(() => {
this.launchTargetAbility();
});
}
private launchTargetAbility(): void {
const abilityContext = getContext(this) as common.UIAbilityContext;
const navigationParams = {
deviceId: '',
bundleName: 'com.example.app',
abilityName: 'TargetAbility',
};
abilityContext.startAbility(navigationParams)
.then((result) => {
console.log('Navigation successful:', JSON.stringify(result));
})
.catch((error) => {
console.error('Navigation failed:', error.code, error.message);
});
}
}
Note: When using the previewer, ensure the target UIAbility has visible: true configured in module.json5 under the exported: true property. Without this configuration, the application may crash. This requirement applies to simulator testing.
Navigation Methods Overview
HarmonyOS provides multiple navigation approaches:
- Internal UIAbility Launch: Start another UIAbility within the same applicasion.
- Internal UIAbility with Result: Launch an internal UIAbility and receive a callback result.
- External Application Launch: Start a UIAbility in another application, supporting both explicit and implicit Want configurations.
- Explicit Want: Precisely match a specific application
- Implicit Want: Use fuzzy matching to select from multiple eligible UIAbilities
- Cross-Application Result: Launch an external UIAbility and retrieve return data.
- Call Interface: Enable UIAbility interaction through IPC, available only for system applications.
Launching System Applications
Opening System Gallery
const systemWant = {
deviceId: '',
bundleName: '',
abilityName: '',
uri: '',
flags: wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
action: 'android.settings.SETTINGS',
parameters: {},
entities: []
};
this.context.startAbility(systemWant, (error) => {
if (error.code) {
console.log('startAbility failed, error.code:', JSON.stringify(error.code),
'error.message:', JSON.stringify(error.message));
return;
}
console.log('System application launched successfully');
});
System Settings Actions
The following table lists common system settings actions available in HarmonyOS 3.1 and 4.0:
| Action | Description |
|---|---|
android.settings.SETTINGS |
Open main settings screen |
android.settings.ACCESSIBILITY_SETTINGS |
Open accessibility settings |
android.settings.ADD_ACCOUNT_SETTINGS |
Open account addition screen |
android.settings.AIRPLANE_MODE_SETTINGS |
Open飞行模式 settings |
android.settings.WIRELESS_SETTINGS |
Open wireless and network settings |
android.settings.APN_SETTINGS |
Open APN configuration |
android.settings.APPLICATION_DETAILS_SETTINGS |
Open app info by package name |
android.settings.APPLICATION_DEVELOPMENT_SETTINGS |
Open developer options |
android.settings.APPLICATION_SETTINGS |
Open installed applications list |
android.settings.MANAGE_ALL_APPLICATIONS_SETTINGS |
Open all applications |
android.settings.MANAGE_APPLICATIONS_SETTINGS |
Open installed apps list |
android.settings.BLUETOOTH_SETTINGS |
Open Bluetooth settings |
android.settings.DATA_ROAMING_SETTINGS |
Open mobile network settings |
android.settings.DATE_SETTINGS |
Open date and time settings |
android.settings.DEVICE_INFO_SETTINGS |
Open device information |
android.settings.DISPLAY_SETTINGS |
Open display settings |
android.settings.INPUT_METHOD_SETTINGS |
Open input method settings |
android.settings.INPUT_METHOD_SUBTYPE_SETTINGS |
Open language selection (API 11+) |
android.settings.INTERNAL_STORAGE_SETTINGS |
Open internal storage settings |
android.settings.MEMORY_CARD_SETTINGS |
Open memory card settings |
android.settings.LOCALE_SETTINGS |
Open language selection |
android.settings.LOCATION_SOURCE_SETTINGS |
Open location services |
android.settings.NETWORK_OPERATOR_SETTINGS |
Open network operator selection |
android.settings.NFC_SETTINGS |
Open NFC settings (API 16+) |
android.settings.PRIVACY_SETTINGS |
Open backup and reset settings |
android.settings.QUICK_LAUNCH_SETTINGS |
Open quick launch settings |
android.settings.SECURITY_SETTINGS |
Open security settings |
android.settings.SOUND_SETTINGS |
Open sound settings |
android.settings.SYNC_SETTINGS |
Open account sync settings |
android.settings.USER_DICTIONARY_SETTINGS |
Open user dictionary |
android.settings.WIFI_IP_SETTINGS |
Open IP settings |
android.settings.WIFI_SETTINGS |
Open WiFi settings |
Cross-Device Navigation
Cross-device ability launching between simulators is not supported in the current version. Attempting such navigation may result in error code 16000009 with message "Cannot operate in wukong mode."