Click here to Skip to main content
Click here to Skip to main content

Android: Set Ringer Silent

By , 17 Apr 2013
 

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.

  • SetRinger2Silent: Sets the ringer to silent mode.
  • SetRinger2Normal: Sets the ringer to normal mode.
  • IsRingerSilent: Checks the mode of the ringer.

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;
    }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Yildirim Kocdag
Software Developer (Senior)
Turkey Turkey
Member
Dr. Yildirim Kocdag is a Computer Engineer from Istanbul. Currently using Android, Objective-c, c#, vb.net, asp.net, javascript, SQL and Oracle. His favourite areas in Computer Science are Compilers, Expert Systems, Digital Image Processing, AI and Extreme Programming.
ykocdag@yahoo.com

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130513.1 | Last Updated 17 Apr 2013
Article Copyright 2013 by Yildirim Kocdag
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid