@capgo/capacitor-android-kiosk

中文文档
8.3.3发布于 2026/10/15MPL-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 4.1万

Android Kiosk Mode plugin for Capacitor - Lock device into kiosk mode with launcher functionality

原始使用文档
文档目录29 节
  1. ➡️ Get started for free
  2. Key features
  3. Documentation
  4. Compatibility
  5. Install
  6. Platform Support
  7. Features
  8. Usage
  9. Basic Kiosk Mode
  10. Launcher Functionality
  11. Hardware Key Control
  12. Complete Example
  13. API
  14. isInKioskMode()
  15. isSetAsLauncher()
  16. enterKioskMode(...)
  17. exitKioskMode()
  18. setAsLauncher()
  19. setAllowedKeys(...)
  20. getPluginVersion()
  21. Interfaces
  22. Android Configuration
  23. 1. MainActivity Setup
  24. 2. AndroidManifest.xml
  25. Important Notes
  26. iOS Alternative
  27. Contributing
  28. License
  29. Author

capacitor-android-kiosk

Lock an Android device into kiosk mode from your Capacitor app: hide system UI, block hardware buttons and run as the home launcher. Built for point of sale, signage and single-purpose devices.

Capgo - Build Capacitor apps with AI, ship updates instantly

Capgo: push fixes to your Capacitor users in minutes, build signed iOS and Android apps without a Mac, and roll back in one click.

➡️ Get started for free

14-day unlimited free trial. No credit card required

🤖 Building with an AI coding agent? Install Capgo skills so Claude Code, Codex, Cursor, Copilot, or Gemini CLI know how to install and use @capgo/capacitor-android-kiosk in your Capacitor app: npx skills add Cap-go/capgo-skills. Then ask your agent: "Add @capgo/capacitor-android-kiosk to my Capacitor app and wire it up." Agent setup guides · Hosted MCP

@capgo/capacitor-android-kiosk for Capacitor apps

Key features

  • Kiosk mode: enterKioskMode() hides system UI and blocks hardware buttons, exitKioskMode() restores them.
  • Launcher: setAsLauncher() opens home screen settings so your app can become the launcher, isSetAsLauncher() checks it.
  • Allowed keys: setAllowedKeys() picks which hardware keys keep working in kiosk mode.
  • State check: isInKioskMode() reports whether kiosk mode is active.
  • Platforms: Android. Android only. iOS and web are not supported.

Documentation

The most complete doc is available here: https://capgo.app/docs/plugins/android-kiosk/

Compatibility

Plugin versionCapacitor compatibilityMaintained
v8.*.*v8.*.*✅
v7.*.*v7.*.*On demand
v6.*.*v6.*.*❌
v5.*.*v5.*.*❌

Note: The major version of this plugin follows the major version of Capacitor. Use the version that matches your Capacitor installation (e.g., plugin v8 for Capacitor 8). Only the latest major version is actively maintained.

Install

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-plugins

Then use the following prompt:

Use the `capacitor-plugins` skill from `cap-go/capacitor-skills` to install the `@capgo/capacitor-android-kiosk` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

npm install @capgo/capacitor-android-kiosk
npx cap sync

Platform Support

This plugin is Android-only. For iOS kiosk mode functionality, please use the device's built-in Guided Access feature.

Features

  • Kiosk Mode: Hide system UI and enter immersive fullscreen mode
  • Keep-alive: Foreground service while in kiosk; stopped when you call exitKioskMode().
  • Session options: restoreAfterReboot tries to opens the app again after reboot; relaunch + relaunchIntervalMinutes tries to bring the UI forward on a timer.
  • Launcher Integration: Set your app as the device launcher/home app
  • Hardware Key Control: Block or allow specific hardware buttons
  • Status Detection: Check if kiosk mode is active or if app is set as launcher
  • Android 6.0+: Supports Android API 23 through Android 15 (API 35)

Usage

Basic Kiosk Mode

import { CapacitorAndroidKiosk } from '@capgo/capacitor-android-kiosk';

// Enter kiosk mode (with optional: restoreAfterReboot, relaunch, relaunchIntervalMinutes)
await CapacitorAndroidKiosk.enterKioskMode();

// Exit kiosk mode
await CapacitorAndroidKiosk.exitKioskMode();

// Check if in kiosk mode
const { isInKioskMode } = await CapacitorAndroidKiosk.isInKioskMode();
console.log('Kiosk mode active:', isInKioskMode);

Launcher Functionality

For full kiosk mode functionality, you need to set your app as the device launcher:

// Open home screen settings for user to select your app as launcher
await CapacitorAndroidKiosk.setAsLauncher();

// Check if app is set as launcher
const { isLauncher } = await CapacitorAndroidKiosk.isSetAsLauncher();
console.log('App is launcher:', isLauncher);

Hardware Key Control

// Allow only volume keys
await CapacitorAndroidKiosk.setAllowedKeys({
  volumeUp: true,
  volumeDown: true,
  back: false,
  home: false,
  recent: false
});

// Block all keys (default)
await CapacitorAndroidKiosk.setAllowedKeys({});

Complete Example

async function setupKioskMode() {
  try {
    // Check if already set as launcher
    const { isLauncher } = await CapacitorAndroidKiosk.isSetAsLauncher();

    if (!isLauncher) {
      // Prompt user to set as launcher
      await CapacitorAndroidKiosk.setAsLauncher();
      alert('Please select this app as your Home app');
      return;
    }

    // Configure allowed keys
    await CapacitorAndroidKiosk.setAllowedKeys({
      volumeUp: true,
      volumeDown: true,
      back: false,
      home: false,
      recent: false,
      power: false
    });

    // Enter kiosk mode
    await CapacitorAndroidKiosk.enterKioskMode();
    console.log('Kiosk mode activated');

  } catch (error) {
    console.error('Failed to setup kiosk mode:', error);
  }
}

API

Capacitor Android Kiosk Plugin for controlling kiosk mode and launcher functionality. This plugin is Android-only. For iOS kiosk mode, use the device's Guided Access feature.

isInKioskMode()

isInKioskMode() => Promise<{ isInKioskMode: boolean; }>

Checks if the app is currently running in kiosk mode.

Returns: Promise<{ isInKioskMode: boolean; }>

Since: 1.0.0


isSetAsLauncher()

isSetAsLauncher() => Promise<{ isLauncher: boolean; }>

Checks if the app is set as the device launcher (home app).

Returns: Promise<{ isLauncher: boolean; }>

Since: 1.0.0


enterKioskMode(...)

enterKioskMode(options?: EnterKioskModeOptions | undefined) => Promise<void>

Enters kiosk mode, hiding system UI and blocking hardware buttons. Also starts a foreground keep-alive service so the app is less likely to be killed by the system. The app must be set as the device launcher for this to work effectively.

ParamTypeDescription
optionsEnterKioskModeOptionsOptional. Omit restoreAfterReboot or relaunch to keep their saved values; pass them when you want to change.

Since: 1.0.0


exitKioskMode()

exitKioskMode() => Promise<void>

Exits kiosk mode, restoring normal system UI and hardware button functionality. Also stops the foreground keep-alive service started in enterKioskMode().

Since: 1.0.0


setAsLauncher()

setAsLauncher() => Promise<void>

Opens the device's home screen settings to allow user to set this app as the launcher. This is required for full kiosk mode functionality.

Since: 1.0.0


setAllowedKeys(...)

setAllowedKeys(options: AllowedKeysOptions) => Promise<void>

Sets which hardware keys are allowed to function in kiosk mode. By default, all hardware keys are blocked in kiosk mode.

ParamTypeDescription
optionsAllowedKeysOptionsConfiguration for allowed keys

Since: 1.0.0


getPluginVersion()

getPluginVersion() => Promise<{ version: string; }>

Get the native Capacitor plugin version.

Returns: Promise<{ version: string; }>

Since: 1.0.0


Interfaces

EnterKioskModeOptions

Optional flags for enterKioskMode.

PropTypeDescription
restoreAfterRebootbooleanAfter reboot, start the app so you can call enterKioskMode() again. Best-effort only (OEM behavior, force-stop). Omit to keep the saved value. Cleared when you call exitKioskMode().
relaunchbooleanPeriodically tries to bring the app to the foreground. Skipped while the screen is off. Often blocked from the background on some devices—being the default launcher, relaxing battery limits, and allowing exact alarms (where required) improve odds. Omit to keep the saved value.
relaunchIntervalMinutesnumberMinutes between relaunch attempts when relaunch is on. Range 5–60; default 15.

AllowedKeysOptions

Configuration options for allowed hardware keys in kiosk mode.

PropTypeDescriptionDefault
volumeUpbooleanAllow volume up buttonfalse
volumeDownbooleanAllow volume down buttonfalse
backbooleanAllow back buttonfalse
homebooleanAllow home buttonfalse
recentbooleanAllow recent apps buttonfalse
powerbooleanAllow power buttonfalse
camerabooleanAllow camera button (if present)false
menubooleanAllow menu button (if present)false

Android Configuration

1. MainActivity Setup

To enable full hardware key blocking, you need to override dispatchKeyEvent in your MainActivity.java:

import android.view.KeyEvent;
import ee.forgr.plugin.android_kiosk.CapacitorAndroidKioskPlugin;

public class MainActivity extends BridgeActivity {
    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        // Get the kiosk plugin
        CapacitorAndroidKioskPlugin kioskPlugin = (CapacitorAndroidKioskPlugin)
            this.getBridge().getPlugin("CapacitorAndroidKiosk").getInstance();

        if (kioskPlugin != null && kioskPlugin.shouldBlockKey(event.getKeyCode())) {
            return true; // Block the key
        }

        return super.dispatchKeyEvent(event);
    }

    @Override
    public void onBackPressed() {
        // Don't call super.onBackPressed() to disable back button
        // Or call the plugin's handleOnBackPressed
    }
}

2. AndroidManifest.xml

Add launcher intent filter to make your app selectable as a launcher:

<activity
    android:name=".MainActivity"
    ...>

    <!-- Existing intent filter -->
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

    <!-- Add this to make app selectable as launcher -->
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.HOME" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

Important Notes

  1. Launcher Requirement: For full kiosk mode functionality (blocking home button, preventing task switching), your app must be set as the device launcher.

  2. Testing: When testing, you can exit kiosk mode programmatically or by setting another app as the launcher.

  3. Android Versions: The plugin uses modern Android APIs for Android 11+ and falls back to older methods for compatibility with Android 6.0+.

  4. Security: This plugin is designed for legitimate kiosk applications. Ensure you provide users with a way to exit kiosk mode.

  5. Battery: Kiosk mode keeps the screen on. Consider implementing your own screen timeout or brightness management.

iOS Alternative

For iOS devices, use the built-in Guided Access feature:

  1. Go to Settings > Accessibility > Guided Access
  2. Turn on Guided Access
  3. Set a passcode
  4. Open your app
  5. Triple-click the side button
  6. Adjust settings and start Guided Access

Contributing

See CONTRIBUTING.md

License

MIT

Author

Martin Donadieu [email protected]

版本与发布记录

@capgo/capacitor-android-kiosk 共发布 26 个版本,首次发布于 2025/11/06;过去 12 个月发布了 25 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.3.3latest2026/10/1525 天前
8.3.22026/10/1327 天前
8.3.12026/10/091 个月前
8.3.02026/10/081 个月前
8.2.122026/10/081 个月前
8.2.112026/10/081 个月前

关于 @capgo/capacitor-android-kiosk 的常见问题

@capgo/capacitor-android-kiosk 是什么?

Android Kiosk Mode plugin for Capacitor - Lock device into kiosk mode with launcher functionality

如何安装 @capgo/capacitor-android-kiosk?

在项目目录运行 npm install @capgo/capacitor-android-kiosk,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capgo/capacitor-android-kiosk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capgo/capacitor-android-kiosk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capgo/capacitor-android-kiosk 可以商用吗?

@capgo/capacitor-android-kiosk 使用 MPL-2.0 许可。弱 Copyleft:可以商用,也可以和闭源代码一起使用;但如果分发时修改了 MPL 授权的文件,这些文件的修改需以 MPL 开源。以上为概括,不构成法律意见,请以许可原文为准。

@capgo/capacitor-android-kiosk 的下载量有多少?

根据 npm 官方下载统计,@capgo/capacitor-android-kiosk 在 2026/10/09 – 2026/11/07 这 30 天内被下载 40,575 次,日均约 1,353 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capgo/capacitor-android-kiosk 还在维护吗?

最新版本 8.3.3 发布于 2026/10/15(25 天前);至今共发布 26 个版本,其中过去 12 个月发布了 25 个;首次发布于 2025/11/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。