Ionic 3 音量键事件捕获

Ionic 3 Volume Key Event Capture

我想要做的是在用户按下 phone 上的提高音量或降低音量按钮时调用我的函数之一。到目前为止我尝试的是使用 cordova 事件,但没有任何成功(当我触摸按钮时没有任何反应)

app.component.ts中:

this.platform.ready().then(() => {
  document.addEventListener("volumeupbutton", this.myFunc, false);
});

myFunc() {
  console.log("it's working");
} 

您可以尝试使用 cordova-plugin-volume-buttons 插件

您可以尝试使用 cordova-volume-buttons 插件

来源:cordova volume button plugin

我刚刚写了一个 Capacitor 插件来解决这个问题。适用于 iOS 和 Android。如果有帮助请给个star吧!

https://github.com/thiagobrez/capacitor-volume-buttons