• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.app.ability.kioskManager (Kiosk Mode Management)
2<!--Kit: Ability Kit-->
3<!--Subsystem: Ability-->
4<!--Owner: @zhu-feimo-->
5<!--Designer: @ccllee1-->
6<!--Tester: @lixueqing513-->
7<!--Adviser: @huipeizi-->
8
9The KioskManager module provides APIs to manage kiosk mode, including entering and exiting kiosk mode.
10
11This module applies only to enterprise applications. In kiosk mode, an enterprise application can lock a device to a single application, ensuring that the UI serves only specific interactive scenarios, such as bank ATM terminals, KTV song-selection systems, and restaurant ordering systems.
12
13> **NOTE**
14>
15> 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.
16>
17> The APIs of this module can be used only in the stage model.
18
19## Modules to Import
20
21```ts
22import { kioskManager } from '@kit.AbilityKit';
23```
24
25## kioskManager.enterKioskMode
26
27enterKioskMode(context: UIAbilityContext): Promise&lt;void&gt;
28
29Enters kiosk mode. This API uses a promise to return the result.
30
31This API applies only to EDM-configured applications that support kiosk mode.
32
33**System capability**: SystemCapability.Ability.AbilityRuntime.Core
34
35**Parameters**
36
37| Name| Type| Mandatory| Description|
38|--------|------|------|------|
39| context | [UIAbilityContext](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md) | Yes| Context of the UIAbility.|
40
41**Return value**
42
43| Type| Description|
44|------|------|
45| Promise&lt;void&gt; | Promise that returns no value.|
46
47**Error codes**
48
49For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
50
51| ID| Error Message|
52|---------|---------|
53| 801 | Capability not supported. |
54| 16000050 | Internal error. |
55| 16000110 | Current application is not in kiosk app list, can not enter kiosk mode. |
56| 16000111 | System is already in kiosk mode, can not enter again. |
57| 16000113 | Current ability is not in foreground. |
58
59**Example**
60
61```ts
62import { common, kioskManager } from '@kit.AbilityKit';
63import { hilog } from '@kit.PerformanceAnalysisKit';
64import { BusinessError } from '@kit.BasicServicesKit';
65
66@Entry
67@Component
68struct Index {
69  private uiAbilityContext: common.UIAbilityContext | undefined =
70    this.getUIContext().getHostContext() as common.UIAbilityContext;
71
72  build() {
73    Column() {
74      Button('enterKioskMode').margin({ top: 30 })
75        .onClick(() => {
76          kioskManager.enterKioskMode(this.uiAbilityContext)
77            .then(() => {
78              hilog.info(0x0000, 'testTag', '%{public}s', 'enterKioskMode success');
79            })
80            .catch((error: BusinessError) => {
81              hilog.error(0x0000, 'testTag', '%{public}s', `enterKioskMode failed:${JSON.stringify(error)}`);
82            });
83        })
84    }
85    .height('100%')
86    .width('100%')
87  }
88}
89```
90
91## kioskManager.exitKioskMode
92
93exitKioskMode(context: UIAbilityContext): Promise&lt;void&gt;
94
95Exits kiosk mode. This API uses a promise to return the result.
96
97This API takes effect only for applications that have entered kiosk mode.
98
99**System capability**: SystemCapability.Ability.AbilityRuntime.Core
100
101**Parameters**
102
103| Name| Type| Mandatory| Description|
104|--------|------|------|------|
105| context | [UIAbilityContext](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md) | Yes| Context of the UIAbility.|
106
107**Return value**
108
109| Type| Description|
110|------|------|
111| Promise&lt;void&gt; | Promise that returns no value.|
112
113**Error codes**
114
115For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Ability Error Codes](errorcode-ability.md).
116
117| ID| Error Message|
118|---------|---------|
119| 801 | Capability not supported. |
120| 16000050 | Internal error. |
121| 16000110 | Current application is not in kiosk app list, can not exit kiosk mode. |
122| 16000112 | Current application is not in kiosk mode, can not exit. |
123
124**Example**
125
126```ts
127import { common, kioskManager } from '@kit.AbilityKit';
128import { hilog } from '@kit.PerformanceAnalysisKit';
129import { BusinessError } from '@kit.BasicServicesKit';
130
131@Entry
132@Component
133struct Index {
134  private uiAbilityContext: common.UIAbilityContext | undefined =
135    this.getUIContext().getHostContext() as common.UIAbilityContext;
136
137  build() {
138    Column() {
139      Button('exitKioskMode').margin({ top: 10 })
140        .onClick(() => {
141          kioskManager.exitKioskMode(this.uiAbilityContext)
142            .then(() => {
143              hilog.info(0x0000, 'testTag', '%{public}s', 'exitKioskMode success');
144            })
145            .catch((error: BusinessError) => {
146              hilog.error(0x0000, 'testTag', '%{public}s', `exitKioskMode failed:${JSON.stringify(error)}`);
147            });
148        })
149    }
150    .height('100%')
151    .width('100%')
152  }
153}
154```
155
156## KioskStatus<sup>20+</sup>
157
158type KioskStatus = _KioskStatus
159
160Defines the kiosk status information, including whether the system is in kiosk mode and the information about the application in kiosk mode.
161
162**System capability**: SystemCapability.Ability.AbilityRuntime.Core
163
164| Type| Description|
165| --- | --- |
166| [_KioskStatus](js-apis-application-KioskStatus.md#kioskstatus) | Kiosk status information, including whether the system is in kiosk mode and the information about the application in kiosk mode.|
167