You can use a class AudioManager.
In this class you are looking for a function setRingerMode().
AudioManager audiomanage = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
audiomanage.setRingerMode(AudioManager.RINGER_MODE_SILENT);
The values you can pass to the function:
Call mode, one of RINGER_MODE_NORMAL, RINGER_MODE_SILENT, or RINGER_MODE_VIBRATE.
You should add this to the manifest file:
android.permission.MODIFY_AUDIO_SETTINGS
source
share