我可以使来电静音,但是我也想阻止当您已经在通话中而又有第二个电话打进来时听到的声音,
这是我用来静音通话的方法:
final AudioManager am = ((AudioManager) this.getSystemService(Context.AUDIO_SERVICE));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mOldStreamVolume = am.getStreamVolume(AudioManager.STREAM_RING);
am.adjustStreamVolume(AudioManager.STREAM_RING, AudioManager.ADJUST_MUTE, 0);
} else {
// deprecated since 22 or 23
am.setStreamMute(AudioManager.STREAM_RING, true);
}