开始入门
复制一个包含安装步骤和完整 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.
您可以使用我们的 AI 助手设置来安装插件。使用以下命令将 Capgo 技能添加到您的 AI 工具中:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下提示:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-volume-buttons` plugin in my project.如果您更喜欢手动设置,请按照以下命令安装插件并遵循以下平台特定的说明:
bun add @capgo/capacitor-volume-buttonsbunx cap sync导入
导入部分import { VolumeButtons } from '@capgo/capacitor-volume-buttons';API概述
API概述部分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
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
音量按钮按下音量按钮按下事件数据。
export interface VolumeButtonPressed { /** Direction of the button press */ direction: VolumeButtonDirection;}VolumeButtonDirection
Section titled “VolumeButtonDirection”音量按键方向
export type VolumeButtonDirection = 'up' | 'down';真实数据来源
Section titled “真实数据来源”本页面由插件生成。 src/definitions.ts当公共 API 上游更改时,请重新运行同步。
从 Getting Started 继续
Section titled “从 Getting Started 继续”如果您正在使用 Getting Started 来规划仪表板和 API 操作,请连接它 使用 @capgo/capacitor-volume-buttons 为原生功能使用 @capgo/capacitor-volume-buttons API 概述 为实现细节使用 API 概述 介绍 为实现细节使用 介绍 API 键 为实现细节使用 API 键 设备 为实现细节使用 设备