1

I am using the AudioManager in my service to control the media volume, but I can only control the media type, which I write in setStreamVolume(). I have tried to use getRingerMode() to get the media type, but the content is my service's.

int currentType = audioManager.getRingerMode();
int currentVoice = audioManager.getStreamVolume(currentType);

audioManager.setStreamVolume(currentType, currentVoice, AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI);

How can I control the other apps volume?

scopchanov
  • 7,966
  • 10
  • 40
  • 68

2 Answers2

2

Ref : how to increase and decrease the volume programmatically in android

AudioManager audioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);


Button upButton = (Button) findViewById(R.id.upButton);
        upButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

//To increase media player volume               
                audioManager.adjustVolume(AudioManager.ADJUST_RAISE, AudioManager.FLAG_PLAY_SOUND);
            }
        });

        Button downButton = (Button) findViewById(R.id.downButton);
        downButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

//To decrease media player volume
                audioManager.adjustVolume(AudioManager.ADJUST_LOWER, AudioManager.FLAG_PLAY_SOUND);             
            }
        });
Ashvin solanki
  • 4,802
  • 3
  • 25
  • 65
1

Thanks for Dewey Reed and Ashvin solanki. I get a inspiretion from Ashvin solanki and Dewey Reed helps me read the Android Source. To get the current media type ,can use adjustVolume() and set the direction value as AudioManager.ADJUST_SAME. For Example : audioManager.adjustVolume(AudioManager.ADJUST_SAME, AudioManager.FLAG_PLAY_SOUND| AudioManager.FLAG_SHOW_UI); Now the AudioControl Window showed,and has the current media type.