Getting Started
复制一个包含安装步骤和本插件的完整 Markdown 指南的配置提示。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-volume-buttons`
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/volume-buttons/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-volume-buttonsbunx cap sync导入
标题:导入import { VolumeButtons } from '@capgo/capacitor-volume-buttons';API 概述
标题:API 概述addListener
标题:addListener监听硬件音量按钮的按压事件
import { VolumeButtons } from '@capgo/capacitor-volume-buttons';
const listener = await VolumeButtons.addListener( 'volumeButtonPressed', (event) => { console.log(`Volume ${event.direction} button pressed`); });
// Remove listener when doneawait listener.remove();removeAllListeners
标题:移除所有监听器移除此插件的所有监听器。
import { VolumeButtons } from '@capgo/capacitor-volume-buttons';
await VolumeButtons.removeAllListeners();getPluginVersion
标题:获取插件版本获取本地 Capacitor 插件版本。
import { VolumeButtons } from '@capgo/capacitor-volume-buttons';
const { version } = await VolumeButtons.getPluginVersion();console.log('Plugin version:', version);类型参考
标题:类型参考VolumeButtonListener
标题:音量按钮监听器音量按钮事件的监听函数。
export type VolumeButtonListener = (event: VolumeButtonPressed) => void;VolumeButtonPressed
VolumeButtonPressed标题音量按钮按下事件数据
export interface VolumeButtonPressed { /** Direction of the button press */ direction: VolumeButtonDirection;}VolumeButtonDirection
VolumeButtonDirection标题音量按钮按下方向
export type VolumeButtonDirection = 'up' | 'down';真实数据来源
真实数据来源标题此页面由插件生成 src/definitions.ts. 当公共API上游更改时,请重新运行同步
从开始就继续
从开始就继续标题If you are using __CAPGO_KEEP_0__ in __CAPGO_KEEP_1__ Getting Started 为 API 的 __CAPGO_KEEP_1__ 使用 @capgo/capacitor-volume-buttons 使用 @capgo/capacitor-volume-buttons 的原生功能 API 简介 API 的实现细节 简介 __CAPGO_KEEP_0__ 的实现细节 API 的密钥 API 的实现细节 设备 __CAPGO_KEEP_0__