跳过内容

开始

GitHub

您可以使用我们的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-buttons
bunx cap sync
import { VolumeButtons } from '@capgo/capacitor-volume-buttons';

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 done
await listener.remove();

removeAllListeners

移除所有监听器

复制到剪贴板

import { VolumeButtons } from '@capgo/capacitor-volume-buttons';
await VolumeButtons.removeAllListeners();

getPluginVersion

复制到剪贴板

Get the native Capacitor plugin version.

import { VolumeButtons } from '@capgo/capacitor-volume-buttons';
const { version } = await VolumeButtons.getPluginVersion();
console.log('Plugin version:', version);

音量按钮监听器

音量按钮监听器

VolumeButtonListener

音量按钮监听器

Listener function for volume button events.

export type VolumeButtonListener = (event: VolumeButtonPressed) => void;

音量按钮按下的事件数据

export interface VolumeButtonPressed {
/** Direction of the button press */
direction: VolumeButtonDirection;
}

音量按钮的方向

export type VolumeButtonDirection = 'up' | 'down';

本页面是根据插件的 src/definitions.ts重新同步公共API时,重新运行上游的同步。

继续从 Getting Started

标题:继续从 Getting Started

如果您正在使用 Getting Started 来规划仪表板和 API 操作,连接它 使用 @capgo/capacitor-volume-buttons 为 native 能力在 Using @capgo/capacitor-volume-buttons 中 API 概述 为 API 概述的实现细节 介绍 为 Introduction 的实现细节 API 密钥 为API Keys的实现细节,和 设备 为设备的实现细节,