How to check current sound profile in Android

Many times in Android development, we need to check the current sound profile. Like it is in normal mode, vibrate mode or silent mode. So for that in Android, they provide AudioManager class which have method that return the current sound profile. Below is the example of it.

AudioManager profileCheck = (AudioManager)getSystemService(Context.AUDIO_SERVICE);

if (profileCheck.getRingerMode() == AudioManager.RINGER_MODE_NORMAL)
    Toast.makeText(getApplicationContext(), "Normal", Toast.LENGTH_LONG).show();
else if (profileCheck.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE)
    Toast.makeText(getApplicationContext(), "Vibrate", Toast.LENGTH_LONG).show();
else if (profileCheck.getRingerMode() == AudioManager.RINGER_MODE_SILENT)
    Toast.makeText(getApplicationContext(), "Silent", Toast.LENGTH_LONG).show();

According to the sound profile you can manage your further actions.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s