Silence Android Phone in Java

前端 未结 2 1774
隐瞒了意图╮
隐瞒了意图╮ 2020-12-13 16:29

How can I silence the android phone in java? A code sample is VERY helpful.

2条回答
  •  情深已故
    2020-12-13 17:02

    You can use the AudioManager class.

    In this class you're looking for setRingerMode() function.

    AudioManager audiomanage = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
    audiomanage.setRingerMode(AudioManager.RINGER_MODE_SILENT);
    

    The values you can pass into the function are:

    The ringer mode, one of RINGER_MODE_NORMAL, RINGER_MODE_SILENT, or RINGER_MODE_VIBRATE.

    You have to add this into the manifest file:

    android.permission.MODIFY_AUDIO_SETTINGS
    

提交回复
热议问题