目录

Obtaining the Senior Mode Status

Use Cases

Since API version 26.0.0, if your app wants to change its senior mode status along with the system-wide Senior mode status, you can use either of the following methods to obtain or listen for the system-wide Senior mode status. This delivers clearer, easier-to-operate content for senior citizens.

  1. Querying the system-wide Senior mode status: When an app is launched, it can call the isSeniorModeEnabled API to query the Senior mode status in the system settings. If the system-wide Senior mode is enabled, the app should also enable its own senior mode. If the system-wide Senior mode is disabled, the app should also disable its senior mode.

  2. Listening for the system-wide Senior mode status: When an app process exists, it can call the onSeniorModeStateChange API provided by Accessibility Kit to listen for the system-wide Senior mode status. When the Senior mode status changes, the app can switch its senior mode status accordingly.

API Description

The following table describes the APIs related to the senior mode of your app and the system.

API Description
isSeniorModeEnabled(): Promise<boolean> Obtains the Senior mode status. It is an asynchronous API.
onSeniorModeStateChange(callback: Callback<boolean>): void Registers a listener for Senior mode status change events.
offSeniorModeStateChange(callback?: Callback<boolean>): void Unregisters a listener for Senior mode status change events.

Development Example

  1. Import the accessibility module and the related common module.

    import { accessibility } from '@kit.AccessibilityKit';
    import { BusinessError } from '@kit.BasicServicesKit';
  2. Listen for system-wide Senior mode status changes.

    Register a listener for system-wide Senior mode status changes in aboutToAppear and unregister the listener in aboutToDisappear.

    @Entry
    @Component
    struct SeniorModeDemo1 {
    
     // Callback for Senior mode status changes. If the return value is true, Senior mode is enabled. Otherwise, Senior mode is disabled.
     callback = (data: boolean) => {
       console.info(`subscribe senior mode state change, result: ${JSON.stringify(data)}`);
     }
    
      aboutToAppear(): void {
        // Register a listener for system-wide Senior mode status changes.
        accessibility.onSeniorModeStateChange(this.callback);
      }
    
    
      aboutToDisappear(): void {
        // Unregister the listener for system-wide Senior mode status changes.
        accessibility.offSeniorModeStateChange(this.callback);
      }
    
      build() {
        // Display the UX.
      }
    }
  3. Query the system-wide Senior mode status.

    @Entry
    @Component
    struct SeniorModeDemo2 {
      aboutToAppear(): void {
        // Call the asynchronous API isSeniorModeEnabled to query the current system-wide Senior mode status. If the return value is true, the system-wide Senior mode is enabled. Otherwise, the system-wide Senior mode is disabled.
        accessibility.isSeniorModeEnabled().then((data: boolean) => {
          console.info(`success data:isSeniorModeEnabled : ${JSON.stringify(data)}`);
        }).catch((err: BusinessError) => {
          console.error(`failed to call isSeniorModeEnabled, Code is ${err.code}, message is ${err.message}`);
        });
      }
    
      build() {
        // Display the UX.
      }
    }