Volume always the same?

前端 未结 1 1230
梦如初夏
梦如初夏 2021-01-16 23:15

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

相关标签:
1条回答
  • 2021-01-16 23:38

    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;
    }
    
    0 讨论(0)
提交回复
热议问题