Reputation: 1967
I am writing an application which handles the following:
Phone volume includes Ringer, video, audio , games volume etc.
I know how to achieve Silent mode through AudioManager
. But for 2-4 , I could not find any helpful code snippets. What do I need to do?
Upvotes: 4
Views: 17059
Reputation: 737
Add this in onCreate()
method of your code and then play around with the 0 value to increase or decrease the volume where 0 means OFF.
AudioManager mgr=null;
mgr=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
mgr.setStreamVolume(AudioManager.STREAM_MUSIC, 0, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
mgr.setStreamVolume(AudioManager.STREAM_RING, 0, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
mgr.setStreamVolume(AudioManager.STREAM_ALARM, 0, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
mgr.setStreamVolume(AudioManager.STREAM_SYSTEM, 0, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
mgr.setStreamVolume(AudioManager.STREAM_NOTIFICATION, 0, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
Upvotes: 20
Reputation: 2500
Check out http://thinkandroid.wordpress.com/2010/04/05/dealing-with-the-android-media-player/
The steps are:
e.g.:
mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);
to get max vol:
int maxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
Upvotes: 3