Logo Icon Logo
A Crowd-sourced Cookbook on Writing Great Android® Apps
GitHub logo Twitter logo OReilly Book Cover Art

Changing Incoming Call Notification to Silent, Vibrate, or Normal

Published? true
FormatLanguage: WikiFormat


You need to put the Android device to silent, vibrate or normal mode


Use Android's AudioManager system service to turn the phone to Normal, Silent and Vibrate modes


Here is a sample application that has 3 buttons to change the phone mode to Silent, Vibrate and Normal:

We instantiate the AudioManager class to be able to use the setRingerMode method. For each of these buttons (silentButton, normalButton and vibrateButton) we have OnclickListeners defined in which we used the AudioManager object to set the ringer mode. We also display a Toast notifying the mode change.

        am= (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
        silentButton = (Button)findViewById(R.id.silent);
        normalButton = (Button)findViewById(R.id.normal);
        vibrateButton = (Button)findViewById(R.id.vibrate);
        //For Silent mode
        silentButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				Toast.makeText(getApplicationContext(), "Silent Mode Activated.", Toast.LENGTH_LONG).show();

        //For Normal mode
        normalButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				Toast.makeText(getApplicationContext(), "Normal Mode Activated", Toast.LENGTH_LONG).show();
        //For Vibrate mode
        vibrateButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				Toast.makeText(getApplicationContext(), "Vibrate Mode Activated", Toast.LENGTH_LONG).show();

This is how the application looks when the Silent button is clicked. (Notice the silent icon in the status bar of the phone.)