Capacitor plugin to listen to volume button presses
npm install @capgo/capacitor-volume-buttons
The most complete doc is available here: https://capgo.app/docs/plugins/volume-buttons/
| Plugin version | Capacitor compatibility | Maintained |
| -------------- | ----------------------- | ---------- |
| v8.\.\ | v8.\.\ | ✅ |
| v7.\.\ | v7.\.\ | On demand |
| v6.\.\ | v6.\.\ | ❌ |
| v5.\.\ | v5.\.\ | ❌ |
> Note: The major version of this plugin follows the major version of Capacitor. Use the version that matches your Capacitor installation (e.g., plugin v8 for Capacitor 8). Only the latest major version is actively maintained.
``bash`
npm install @capgo/capacitor-volume-buttons
npx cap sync
* addListener('volumeButtonPressed', ...)
* removeAllListeners()
* getPluginVersion()
* Interfaces
* Type Aliases
Capacitor Volume Buttons Plugin for detecting hardware volume button presses.
`typescript`
addListener(eventName: 'volumeButtonPressed', listenerFunc: VolumeButtonListener) => Promise
Listen for presses on the hardware volume buttons.
| Param | Type | Description |
| ------------------ | --------------------------------------------------------------------- | ------------------------------------------------------ |
| eventName | 'volumeButtonPressed' | - The event name (must be 'volumeButtonPressed') |
| listenerFunc | VolumeButtonListener | - The function to call when a volume button is pressed |
Returns: Promise<PluginListenerHandle> & PluginListenerHandle
Since: 1.0.0
--------------------
`typescript`
removeAllListeners() => Promise
Removes all listeners for this plugin.
Since: 1.0.0
--------------------
`typescript`
getPluginVersion() => Promise<{ version: string; }>
Get the native Capacitor plugin version.
Returns: Promise<{ version: string; }>
Since: 1.0.0
--------------------
#### PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| remove | () => Promise<void> |
#### VolumeButtonPressed
Event data for volume button press.
| Prop | Type | Description |
| --------------- | ----------------------------------------------------------------------- | ----------------------------- |
| direction` | VolumeButtonDirection | Direction of the button press |
#### VolumeButtonListener
Listener function for volume button events.
(event: VolumeButtonPressed): void
#### VolumeButtonDirection
Direction of volume button press.
'up' | 'down'