Reputation: 51
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?
Upvotes: 1
Views: 999
Reputation: 51
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.
Upvotes: 1
Reputation: 4809
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);
}
});
Upvotes: 1