sajjoo
sajjoo

Reputation: 6624

disable volume option in sound settings android

Is it possible to disable the volume in sound settings? I have googled but could not found satisfied result.

I know there are some apps in Android Market which disable and enable the volume by just pressing the icon.

Upvotes: 0

Views: 5942

Answers (3)

Bhargav Panchal
Bhargav Panchal

Reputation: 1189

There are four kind of sound setting in android 1)Alarm 2)Music 3)Ring Tone 4)Notification First Create object of AudioManager amanager; IF you want to set Volume use this code

For Notification

AudioManager amanager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
amanager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, AudioManager.FLAG_SHOW_UI + AudioManager.FLAG_PLAY_SOUND);

For Alerm

amanager.setStreamVolume(AudioManager.STREAM_ALARM,AudioManager.FLAG_SHOW_UI + AudioManager.FLAG_PLAY_SOUND);

For Music

amanager.setStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.FLAG_SHOW_UI + AudioManager.FLAG_PLAY_SOUND);

For Ring Tone

amanager.setStreamVolume(AudioManager.STREAM_RING,AudioManager.FLAG_SHOW_UI + AudioManager.FLAG_PLAY_SOUND);

Upvotes: 2

jmishra
jmishra

Reputation: 2081

Look in the AudioManager class and try either of this

AudioManager volumeControl = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
volumeControl.setStreamVolume(AudioManager.STREAM_MUSIC, 20, 0);

OR

AudioManager volumeControl = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
volumeControl.setStreamMute(AudioManager.STREAM_MUSIC, true);

Upvotes: 3

zapl
zapl

Reputation: 63955

If you want to disable changing the volume:

Not possible. Those apps create a Service that constantly monitors the volume and reset it back to what it was once you change it.

If you want to change the volume: AudioManager.adjustVolume()

To turn volume on/off: AudioManager.setStreamMute()

Upvotes: 1

Related Questions