-2

I was wondering whether it might be possible to write an app in which the user can go through data by clicking the volume up or down headphone control buttons on their headphones?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Dave Gee
  • 47
  • 1
  • 1
  • 10

1 Answers1

1

Yes, you can do that. You'll need to AudioManager service and extra permission in manifest. You can register callbacks for 'volume up and down' events. See https://developer.android.com/reference/android/media/AudioManager.html

Alex Shutov
  • 3,217
  • 2
  • 13
  • 11
  • thanks but am I able to also program headphone controls with that class? (vol up/down,play,pause) – Dave Gee Oct 30 '16 at 20:34
  • play/ pause is controlled by player, you can increase and decrease volume by adjustStreamVolume(..) method and also switch audio streams (speakerphone/ loudspeaker) – Alex Shutov Oct 30 '16 at 20:40
  • I don't quite get how to do something completely different with the controls than handle audio yet! My mission here in fact is to let the user swipe through lets say pictures by clicking for example vol up (my app has nothing to do with audio!) – Dave Gee Oct 30 '16 at 20:56
  • http://stackoverflow.com/questions/9162705/android-how-to-listen-for-volume-button-events may this will help - listen for that key as 'hardware keyboard' – Alex Shutov Oct 30 '16 at 21:16