Reputation: 4437
I am working in an android app and I need to make an optionMenu
with an option to disable/enable the sounds in the app.
Is it possible in android have full control over the volume of the app? Is there any method that could do that? Must I do this with code?
Thanks
Upvotes: 2
Views: 1649
Reputation: 1217
By using AudioManager you can get current volume level and max volume level. At the time of button click/ option select you can control the volume level also. Here is the code.I hope this will help you to set volume.
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
int curVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
To Set Volume
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,vol_level, 0);
Upvotes: 1