3 Replies
      Latest reply on Mar 26, 2020 5:19 AM by Claude31
      kberawala Level 1 Level 1 (0 points)

        Is there any way to listen for hardware button events (volume up/down, power button) in the background?


        I am developing a safety app and would like to trigger an emergency event on e.g. pressing the volume button OR power button 5 times continuously.


        The app currently has the feature, but the user has to open the app to trigger it and that's the initial criticism. the user won't have enough time to open the app in an emergency.

        • Re: Hardware buttons
          Claude31 Level 8 Level 8 (8,505 points)

          No, you can't with published API.


          And it is on purpose, to avoid changing the expected behavior of buttons .

          If your app is in foreground, you can keep the buttons you need on screen for easy access to user.

          if app is in background, changing the behavior of buttons would be a problem for user (launching an alert as he/she is just trying to change volume for music)

          if app is closed, nothing can happen of course.


          So, you should look for a different design.