I have the following code, and I want to get the difference of the previous volume before holding the volume button and the current volume. But, when I was debugging, I fou
You probably aren't changing the media volume on your device. To verify go to Settings->Sound & Notification and try changing the Media volume found there.
You probably also want to update update your previousVolume
after a change too:
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
int currentVolume = audio.getStreamVolume(AudioManager.STREAM_MUSIC);
processVolumeChange(currentVolume);
}
public void processVolumeChange(int currentVolume) {
MyService mService = new MyService();
mService.volumeCheck(previousVolume - currentVolume); //Method in my service
previousVolume = currentVolume;
}