is it possible to mute a call while recording the sound in android

喜你入骨 提交于 2019-12-06 10:36:26

This answer works to mute your microphone during a call:

Boolean isMuted = false;

Then in your event, say an onClick

AudioManager audioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
if(!isMuted){

   if((audioManager.getMode()== AudioManager.MODE_IN_CALL)||(audioManager.getMode()== AudioManager.MODE_IN_COMMUNICATION)){
   audioManager.setMicrophoneMute(true);
  }
  isMuted = true;

 }else{

  if((audioManager.getMode()== AudioManager.MODE_IN_CALL)||(audioManager.getMode()== AudioManager.MODE_IN_COMMUNICATION)){
    audioManager.setMicrophoneMute(false);
    }
  isMuted = false;
 }

Remember to enable permissions in your manifest:

<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

Step 1. set permission in manifest

<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

Step 2. reverse microphone status

AudioManager audioManager = 
     (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
if (audioManager!=null) {
     audioManager.setMicrophoneMute(!audioManager.isMicrophoneMute());
}

I couldn't make AudioManager.setMicrophoneMute(boolean) work on my Honor device, but I found another way to do this. I needed this funcionality in my custom dial app, so I already had custom InCallService, intercepting all calls. This class has method setMuted(boolean state) which works perfectly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!