Silence Android Phone in Java

How to disable android phone in java? Sample code is very useful.

+5
source share
2 answers

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
+20
source

Use class methods AudioManagerto mute sound.

For example, to turn off the call, use manager.setRingerMode(AudioManager.RINGER_MODE_SILENT)

You can get an instance AudioManagerby callingContext.getSystemService(Context.AUDIO_SERVICE)


http://developer.android.com/reference/android/media/AudioManager.html#setRingerMode(int)

+3

All Articles