'Ionic 3 Volume Key Event Capture
What I want to do is call one of my functions whenever the user presses the volume up or the volume down buttons on the phone. What I tried so far is using the cordova events, but without any success (nothing happens when I touch the buttons)
In app.component.ts
:
this.platform.ready().then(() => {
document.addEventListener("volumeupbutton", this.myFunc, false);
});
myFunc() {
console.log("it's working");
}
Solution 1:[1]
You can try with cordova-plugin-volume-buttons plugin
Solution 2:[2]
Solution 3:[3]
I just wrote a Capacitor plugin to solve this. Works on both iOS and Android. If it helps please give it a star!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dhananjay Chaudhari |
Solution 2 | Srinath gunnu |
Solution 3 | thiagobrez |