Audio Manager

August 8,2016

In order to use AndroidManager class, you have to first create an object of AudioManager class by calling the getSystemService() method. Its syntax is given below.

private AudioManager myAudioManager;
myAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);

Once you instantiate the object of AudioManager class, you can use setRingerMode method to set the audio or ringer profile of your device. Its syntax is given below.

myAudioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);

The method setRingerMode takes an integer number as a parameter. For each mode , an integer number is assigned that will differentiate between different modes. The possible modes are.

Sr.No Mode & Description
1 RINGER_MODE_VIBRATE

This Mode sets the device at vibrate mode.

2 RINGER_MODE_NORMAL

This Mode sets the device at normal(loud) mode.

3 RINGER_MODE_SILENT

This Mode sets the device at silent mode.

Once you have set the mode , you can call the getRingerMode() method to get the set state of the system. Its syntax is given below.

int mod = myAudioManager.getRingerMode();

Apart from the getRingerMode method, there are other methods available in the AudioManager class to control the volume and other modes. They are listed below.

Sr.No Method & description
1 adjustVolume(int direction, int flags)

This method adjusts the volume of the most relevant stream

2 getMode()

This method returns the current audio mode

3 getStreamMaxVolume(int streamType)

This method returns the maximum volume index for a particular stream

4 getStreamVolume(int streamType)

This method returns the current volume index for a particular stream

5 isMusicActive()

This method checks whether any music is active.

6 startBluetoothSco()

This method Start bluetooth SCO audio connection

7 stopBluetoothSco()

This method stop bluetooth SCO audio connection.

Leave a comment