capacitor-community / volume-buttons

Capacitor Volume Buttons. The plugin enables to listen to hardware volume button presses. This plugin is based on https://github.com/thiagobrez/capacitor-volume-buttons
MIT License
7 stars 2 forks source link

Prevent default buttons behaviour in Android #3

Closed 1g0rrr closed 3 months ago

1g0rrr commented 4 months ago

How about to add flag to prevent apearing volume indicator on Android? I'm tryint to make "Push to talk" function in my app by pressing volume button. That's why I need to override default behaviour so volume panel not showed up.

By now I made a "hack" and change KeyEvent.ACTION_UP to KeyEvent.ACTION_DOWN in the line: boolean isKeyUp = event.getAction() == KeyEvent.ACTION_UP; Which is work for my case and prevent volume panel from appearing. But maybe it's better to make cleaner and more universal solution?

p-caetano commented 3 months ago

Hi. I just migrated a simple app from cordova to capacitor, and it was working without any plugin, using: @HostListener('document:volumeupbutton') @HostListener('document:volumedownbutton')

I quickly checked the cordova-android plugin and they simply consume the key down events without any action: https://github.com/apache/cordova-android/blob/4742358601e892a8c8816ef8b1827dfdf7b3754e/framework/src/org/apache/cordova/CordovaWebViewImpl.java#L615

For my usecase, I would like to receive the event on key down, because I'm using it in a timer where the precision is important. But I agree that the default behavior should be on key up.

ryaa commented 3 months ago

PR is welcome :)

ryaa commented 3 months ago

@1g0rrr The required change has been implemented. New suppressVolumeIndicator option has been introduced - see here. For more details about new release v1.0.2 please see CHANGELOG

1g0rrr commented 3 months ago

@ryaa That's awesome! Thank! I'll try it in my app and check on different devices

p-caetano commented 3 months ago

@ryaa Thanks. I started an implementation, but I was yet finding out how the plugin system works. I'm trying also to listen the key down event. I'll give feedback later.