0

I am creating an Android app which has a seekbar and it controls the media volume of android device. Now, I have to update the seekbar also if there is any change in media volume of the device either by using volume button or by changing default volume seekbar of the device.

So my question is: Is there any way to listen for volume change in android so that I can update my app specific seekbar when there is a change in volume of the device?

I have found a way of doing it. But, it gets triggered whenever there is any change in Setting.

public class SettingsContentObserver extends ContentObserver {
    private AudioManager audioManager;

    public SettingsContentObserver(Context context, Handler handler) {
        super(handler);
        audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    }

    @Override
    public boolean deliverSelfNotifications() {
        return false;
    }

    @Override
    public void onChange(boolean selfChange) {
        int currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);

        Log.d(TAG, "Volume now " + currentVolume);
    }
}

Is there any better way of doing it? Please suggest. Thanks in advance

  • try this: https://stackoverflow.com/questions/11318933/listen-to-volume-changes-events-on-android – Nigel Brown Jul 23 '18 at 17:58
  • Hi @NigelBrown: Thanks for the link. The answer does the same thing which I have done so far. I want something which listens to volume change only but the answer here listens to any changes done in Setting. So, It will give you many callbacks. – Prashant Sharma Jul 23 '18 at 18:12

0 Answers0