0

If an user presses volume key up and down, is it possible to detect it in my broadcast receiver?

I need the full code. This question have been already asked on http://stackoverflow.com but was not answered properly.

I have been searching for a solution to this question from the past three weeks but unable to find proper answer.

I want code snipet for:

1)     public class MainActivity extends Activity {}
2)     public class VolumeKeyReceiver extends BroadcastReceiver  {}
3)     AndroidManifest.xml

please help!!

Unheilig
  • 16,196
  • 193
  • 68
  • 98

1 Answers1

0

There is not a supported broadcast event for volume button press (change). There are 2 ways to listen for volume button presses.

1) ContentObserver. See How to register ContentObserver for media volume change?

2) onKeyEvent. See Android - Volume Buttons used in my application

If you want a BroadcastReceiver, one of the two above can fire a broadcast event - sendBroadcast see http://developer.android.com/reference/android/content/Context.html#sendBroadcast(android.content.Intent)

Community
  • 1
  • 1
Dave Truby
  • 193
  • 1
  • 5