Skip to main content
@capgo/capacitor-volume-buttons Device APIs Open source

Volume Buttons Capacitor plugin

Capture hardware volume button presses for custom app controls and shortcuts

Install

bun add @capgo/capacitor-volume-buttons bunx cap sync
npm, pnpm or yarn
  • npm install @capgo/capacitor-volume-buttons
  • pnpm add @capgo/capacitor-volume-buttons
  • yarn add @capgo/capacitor-volume-buttons

Guide

How to use Volume Buttons in Capacitor

Test on device

Download the Capgo app, then scan the QR code.

Volume Buttons plugin preview QR code

Using @capgo/capacitor-volume-buttons

Capacitor Volume Buttons Plugin for detecting hardware volume button presses.

Install

bun add @capgo/capacitor-volume-buttons
bunx cap sync

bunx cap sync copies the plugin's native code into your native projects. Run it again after every plugin upgrade.

Import

import { VolumeButtons } from '@capgo/capacitor-volume-buttons';

API at a glance

Method Description
addListener Listen for presses on the hardware volume buttons.
removeAllListeners Removes all listeners for this plugin.
getPluginVersion Get the native Capacitor plugin version.

Examples

addListener()

Listen for presses on the hardware volume buttons.

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()

Removes all listeners for this plugin.

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);

Listen to events

addListener returns a handle. Call handle.remove() when the screen unmounts, or VolumeButtons.removeAllListeners() to clear every listener.

Full reference

Keep going from Using @capgo/capacitor-volume-buttons

If you are using Using @capgo/capacitor-volume-buttons to plan native plugin work, connect it with @capgo/capacitor-volume-buttons for the implementation detail in @capgo/capacitor-volume-buttons, Getting Started for the implementation detail in Getting Started, Capgo Plugin Directory for the product workflow in Capgo Plugin Directory, Capacitor Plugins by Capgo for the implementation detail in Capacitor Plugins by Capgo, and Adding or Updating Plugins for the implementation detail in Adding or Updating Plugins.

FAQ

Volume Buttons plugin FAQ

How do I install the Volume Buttons plugin in a Capacitor app?

Run "bun add @capgo/capacitor-volume-buttons" (or "npm install @capgo/capacitor-volume-buttons"), then run "bunx cap sync" so the iOS and Android projects pick up the native code. Import it from "@capgo/capacitor-volume-buttons" in your app code.

Does @capgo/capacitor-volume-buttons work with React, Vue and Angular?

Yes. Volume Buttons is a Capacitor package, so it works with any web framework that runs inside Capacitor, including Ionic, React, Vue, Angular, Svelte and plain JavaScript.

Which Capacitor version does @capgo/capacitor-volume-buttons support?

Capgo plugins follow Capacitor's major version: use the plugin major version that matches your Capacitor major version (for example plugin v8 with Capacitor 8). The compatibility table in the GitHub README lists the maintained versions.

Is @capgo/capacitor-volume-buttons free and open source?

Yes. The source code is public on GitHub at https://github.com/Cap-go/capacitor-volume-buttons/ and the package is free to install from npm. Bug reports and pull requests are welcome.

Can I update code that uses Volume Buttons without an App Store review?

Installing or upgrading the plugin changes native code, so it needs a new store build. After that, JavaScript, HTML and CSS changes that call the plugin can ship instantly with Capgo live updates.

Ship Volume Buttons changes without waiting for app review

Once the plugin is in your store build, Capgo live updates push your JavaScript, HTML and CSS changes to users in minutes.

Start with Capgo