开始使用
复制一个包含安装步骤和此插件的完整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 syncimport { VolumeButtons } from '@capgo/capacitor-volume-buttons';addListener
Section titled “添加监听器”监听硬件音量按钮的按压。
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
Section titled “removeAllListeners”移除此插件的所有监听器。
import { VolumeButtons } from '@capgo/capacitor-volume-buttons';
await VolumeButtons.removeAllListeners();getPluginVersion
Section titled “getPluginVersion”获取本地 Capacitor 插件版本。
import { VolumeButtons } from '@capgo/capacitor-volume-buttons';
const { version } = await VolumeButtons.getPluginVersion();console.log('Plugin version:', version);VolumeButtonListener
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. 当 upstream 的公共 API 变更时,请重新同步。