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.