开始使用
复制一个包含安装步骤和本插件的完整Markdown指南的设置命令。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-android-kiosk`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/android-kiosk/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
bun add @capgo/capacitor-android-kioskbunx cap sync导入
导入import { CapacitorAndroidKiosk } from '@capgo/capacitor-android-kiosk';API概述
API概述isInKioskMode
__CAPGO_KEEP_1__检查应用是否处于全屏模式。
import { CapacitorAndroidKiosk } from '@capgo/capacitor-android-kiosk';
const { isInKioskMode } = await CapacitorAndroidKiosk.isInKioskMode();console.log('Kiosk mode active:', isInKioskMode);isSetAsLauncher
__CAPGO_KEEP_2__检查应用是否设置为设备启动器(主应用)。
import { CapacitorAndroidKiosk } from '@capgo/capacitor-android-kiosk';
const { isLauncher } = await CapacitorAndroidKiosk.isSetAsLauncher();console.log('Is launcher:', isLauncher);enterKioskMode
Section titled “enterKioskMode”进入全屏模式,隐藏系统UI并阻止硬件按钮。 此外,还启动了一个前台保活服务,以便系统杀死应用的概率降低。 此功能需要将应用设置为设备的启动器。
import { CapacitorAndroidKiosk } from '@capgo/capacitor-android-kiosk';
await CapacitorAndroidKiosk.enterKioskMode();exitKioskMode
Section titled “exitKioskMode”退出全屏模式,恢复正常的系统UI和硬件按钮功能。 此外,还停止了在enterKioskMode()中启动的前台保活服务。
import { CapacitorAndroidKiosk } from '@capgo/capacitor-android-kiosk';
await CapacitorAndroidKiosk.exitKioskMode();console.log('Exited kiosk mode');setAsLauncher
Section titled “setAsLauncher”打开设备的主屏幕设置,允许用户将此应用设置为启动器。 此功能是全屏模式功能的必要条件。
import { CapacitorAndroidKiosk } from '@capgo/capacitor-android-kiosk';
await CapacitorAndroidKiosk.setAsLauncher();// User will be prompted to select this app as the home appsetAllowedKeys
Section titled “setAllowedKeys”设置在全屏模式下允许功能的硬件键。 默认情况下,全屏模式下所有硬件键都被阻止。
import { CapacitorAndroidKiosk } from '@capgo/capacitor-android-kiosk';
// Allow volume keys onlyawait CapacitorAndroidKiosk.setAllowedKeys({ volumeUp: true, volumeDown: true, back: false, home: false, recent: false});类型参考
类型参考EnterKioskModeOptions
进入全屏模式选项全屏模式下的可选标志 enterKioskMode.
export interface EnterKioskModeOptions { /** * After 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()`. */ restoreAfterReboot?: boolean;
/** * Periodically 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. */ relaunch?: boolean;
/** Minutes between relaunch attempts when `relaunch` is on. Range 5–60; default 15. */ relaunchIntervalMinutes?: number;}AllowedKeysOptions
允许的硬件键配置选项复制到剪贴板
export interface AllowedKeysOptions { /** * Allow volume up button * @default false */ volumeUp?: boolean;
/** * Allow volume down button * @default false */ volumeDown?: boolean;
/** * Allow back button * @default false */ back?: boolean;
/** * Allow home button * @default false */ home?: boolean;
/** * Allow recent apps button * @default false */ recent?: boolean;
/** * Allow power button * @default false */ power?: boolean;
/** * Allow camera button (if present) * @default false */ camera?: boolean;
/** * Allow menu button (if present) * @default false */ menu?: boolean;}重新同步公共__CAPGO_KEEP_0__时请注意上游的变化。 src/definitions.ts重新同步公共API时请注意上游的变化。
继续从 Getting Started
标题:继续从 Getting Started如果您正在使用 Getting Started 来规划仪表板和 API 操作,连接它与 使用 @capgo/capacitor-android-kiosk 为 native 能力在使用 @capgo/capacitor-android-kiosk 中 API 概述 为 API 概述 的实现细节 介绍 为 介绍 的实现细节 API 密钥 为API Keys的实现细节,和 设备 为设备的实现细节,