openharmony 鸿蒙 js-apis-app-ability-kioskManager

2026-08-25 浏览 (1)

@ohos.app.ability.kioskManager (Kiosk Mode Management)

The KioskManager module provides APIs to manage kiosk mode, including entering and exiting kiosk mode.

Kiosk mode is a dedicated device lockdown mode that ensures the device UI serves only specific interaction scenarios. In this mode, device usage is confined to predetermined applications. A typical example is a bank ATM, where users can only interact with the ATM software and cannot exit it or access any other functions.

NOTE

  • The initial APIs of this module are supported since API version 20. Newly added APIs will be marked with a superscript to indicate their earliest API version.
  • The APIs of this module can be used only in the stage model.
  • The APIs of this module are available only to applications that have been configured to support Kiosk mode via setAllowedKioskApps.

Modules to Import

import { kioskManager } from '@kit.AbilityKit';

kioskManager.enterKioskMode

enterKioskMode(context: UIAbilityContext): Promise<void>

Enters kiosk mode. This API uses a promise to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Device behavior differences: This API can be properly called only on phones, PC/2-in-1 devices, and tablets. On other devices, it returns the error code 801.

Parameters

NameTypeMandatoryDescription
contextUIAbilityContextYesContext of the UIAbility that needs to enter kiosk mode.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Ability Error Codes.

IDError Message
801Capability not supported.
16000050Failed to connect to the system service.
16000110The current application is not in Kiosk app list and cannot enter Kiosk mode.
16000111The system is already in Kiosk mode and cannot enter Kiosk mode again.
16000113Current ability is not in foreground.

Example

import { common, kioskManager } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { BusinessError } from '@kit.BasicServicesKit';

@Entry
@Component
struct Index {
  private uiAbilityContext: common.UIAbilityContext|undefined =
    this.getUIContext().getHostContext() as common.UIAbilityContext;

  build() {
    Column() {
      Button('enterKioskMode').margin({ top: 30 })
        .onClick(() => {
          kioskManager.enterKioskMode(this.uiAbilityContext)
            .then(() => {
              hilog.info(0x0000, 'testTag', '%{public}s', 'enterKioskMode success');
            })
            .catch((error: BusinessError) => {
              hilog.error(0x0000, 'testTag', '%{public}s', `enterKioskMode failed:${JSON.stringify(error)}`);
            });
        })
    }
    .height('100%')
    .width('100%')
  }
}

kioskManager.exitKioskMode

exitKioskMode(context: UIAbilityContext): Promise<void>

Exits kiosk mode. This API uses a promise to return the result.

This API takes effect only for applications that have entered kiosk mode.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Device behavior differences: This API can be properly called only on phones, PC/2-in-1 devices, and tablets. On other devices, it returns the error code 801.

Parameters

NameTypeMandatoryDescription
contextUIAbilityContextYesContext of the UIAbility that needs to exit kiosk mode.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Ability Error Codes.

IDError Message
801Capability not supported.
16000050Failed to connect to the system service.
16000110The current application is not in Kiosk app list and cannot enter Kiosk mode.
16000112The current application is not in Kiosk mode and cannot exit Kiosk mode.

Example

import { common, kioskManager } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { BusinessError } from '@kit.BasicServicesKit';

@Entry
@Component
struct Index {
  private uiAbilityContext: common.UIAbilityContext|undefined =
    this.getUIContext().getHostContext() as common.UIAbilityContext;

  build() {
    Column() {
      Button('exitKioskMode').margin({ top: 10 })
        .onClick(() => {
          kioskManager.exitKioskMode(this.uiAbilityContext)
            .then(() => {
              hilog.info(0x0000, 'testTag', '%{public}s', 'exitKioskMode success');
            })
            .catch((error: BusinessError) => {
              hilog.error(0x0000, 'testTag', '%{public}s', `exitKioskMode failed:${JSON.stringify(error)}`);
            });
        })
    }
    .height('100%')
    .width('100%')
  }
}

KioskStatus

type KioskStatus = _KioskStatus

Defines the kiosk status information, including whether the system is in kiosk mode and the information about the application in kiosk mode.

System capability: SystemCapability.Ability.AbilityRuntime.Core

TypeDescription
_KioskStatusKiosk status information, including whether the system is in kiosk mode and the information about the application in kiosk mode.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 js-apis-app-ability-appServiceExtensionAbility

openharmony 鸿蒙 js-apis-inner-wantAgent-triggerInfo-sys

openharmony 鸿蒙 js-apis-inner-wantAgent-wantAgentInfo-sys

openharmony 鸿蒙 js-apis-appControl-sys

openharmony 鸿蒙 js-apis-app-ability-environmentCallback

openharmony 鸿蒙 js-apis-inner-application-missionInfo-sys

openharmony 鸿蒙 js-apis-bundleManager-sharedBundleInfo-sys

openharmony 鸿蒙 js-apis-inner-application-continueMissionInfo-sys

openharmony 鸿蒙 js-apis-inner-application-appServiceExtensionContext

openharmony 鸿蒙 js-apis-bundleManager-businessAbilityInfo-sys

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/G1X4X3D1