Click here to Skip to main content
Full site     10M members (33.5K online)    

Android: Set Ringer Silent

Introduction

This article helps you to set your Android device ringer mode to silent and normal, and check the last mode.

Using the code

The three functions below help you change and check the mode of your device ring. You can write an application that checks the incoming call then if it is a number not in Contacts, the ringer can be set to Silent mode, and after the call you can set it back to normal mode.

Set Ringer to Silent Mode

public void setRinger2Silent()
{       
    AudioManager audioManager= (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
    audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); 
}

Set Ringer to Normal Mode

public void setRinger2Normal()
{       
    AudioManager audioManager= (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
    audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); 
}

Check if the Mode is Silent

public boolean IsRingerSilent()
{
    AudioManager audioManager = 
       (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
    if(audioManager.getRingerMode()==AudioManager.RINGER_MODE_SILENT)
    {
        return true;
    }
    else
    {
        return false;
    }
}
 
You must Sign In to use this message board.
Search 
Per page   
-- There are no messages in this forum --

Last Updated 17 Apr 2013 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2013