However, if your app plays sounds at irregular intervals then you'd notice that the volume can only be controlled while they are playing.
So how can you change the volume of the sound effects while you're in the app? Amazingly, it involves no overriding of event listeners for buttons or implementing of listeners.
During your Activity.onCreate() call, simply add this magical one liner:
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
That's it! Now the volume buttons will behave.
I could not find that in the documentation for the life of me, but it was scattered across a few StackOverflow questions.
[ Source ]