What is the differences between MODE_IN_CALL, MODE_IN_COMMUNICATION, MODE_CALL_SCREENING?

3.2k views Asked by At

This is what the file says, but I can't fully understand.

/* modes for setMode/getMode/setRoute/getRoute */
    /**
     * Audio harware modes.
     */
    /**
     * Invalid audio mode.
     */
    public static final int MODE_INVALID            = AudioSystem.MODE_INVALID;
    /**
     * Current audio mode. Used to apply audio routing to current mode.
     */
    public static final int MODE_CURRENT            = AudioSystem.MODE_CURRENT;
    /**
     * Normal audio mode: not ringing and no call established.
     */
    public static final int MODE_NORMAL             = AudioSystem.MODE_NORMAL;
    /**
     * Ringing audio mode. An incoming is being signaled.
     */
    public static final int MODE_RINGTONE           = AudioSystem.MODE_RINGTONE;
    /**
     * In call audio mode. A telephony call is established.
     */
    public static final int MODE_IN_CALL            = AudioSystem.MODE_IN_CALL;
    /**
     * In communication audio mode. An audio/video chat or VoIP call is established.
     */
    public static final int MODE_IN_COMMUNICATION   = AudioSystem.MODE_IN_COMMUNICATION;
    /**
     * Call screening in progress. Call is connected and audio is accessible to call
     * screening applications but other audio use cases are still possible.
     */
    public static final int MODE_CALL_SCREENING     = AudioSystem.MODE_CALL_SCREENING;

Could you please explain them with examples?

At the moment, I use video chat service on WebView and I get MODE_CALL_SCREENING, it uses media volume, It should use 'calling' volume. How can I force it?

2

There are 2 answers

1
user16930239 On

MODE_IN_CALL
You are talking to someone over audio only call (normal telephone call)

MODE_IN_COMMUNICATION
you are video & audio chatting with your friend or calling them on VoIP

MODE_CALL_SCREENING
your phone is ringing and you are checking then number before you answer the phone

4
I_Al-thamary On

The mode parameter is defined in the AudioSystem class to set the state of the phone

MODE_IN_CALL: Incoming call mode. A phone call is established.

Constant Value: 2 (0x00000002)

public static final int MODE_IN_CALL 





private void setAudioNormal() {
    AudioManager audioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
    audioManager.setMode(AudioManager.MODE_NORMAL);
    audioManager.setSpeakerphoneOn(false);
  }
}

Another example

import android.media.AudioManager; 
public void startOutgoingRinger(OutgoingRinger.Type type) {
    AudioManager audioManager = ServiceUtil.getAudioManager(context);
    audioManager.setMicrophoneMute(false);

    if (type == OutgoingRinger.Type.SONAR) {
        audioManager.setSpeakerphoneOn(false);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
    } else {
        audioManager.setMode(AudioManager.MODE_IN_CALL);
    }

    outgoingRinger.start(type);
}

MODE_IN_COMMUNICATION: In communication audio mode. An audio/video chat or VoIP communications are established.

Constant Value: 3 (0x00000003)

public static final int MODE_IN_COMMUNICATION



  private void chooseVoiceMode() {
      AudioManager audioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
      if(mAudioConfiguration.aec) {
        audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
        audioManager.setSpeakerphoneOn(true);
      } else {
        audioManager.setMode(AudioManager.MODE_NORMAL);
        audioManager.setSpeakerphoneOn(false);
      }
    }

MODE_CALL_SCREENING: Call screening in progress. There is a call connected but the audio is not in use. Call screening: It is the process of identifying an incoming caller, giving information about the caller, and determining how best to respond to that call.

Constant Value: 4 (0x00000004)

public static final int MODE_CALL_SCREENING





public int getMode() {
    final IAudioService service = getService();
    try {
        int mode = service.getMode();
        int sdk;
        try {
            sdk = getContext().getApplicationInfo().targetSdkVersion;
        } catch (NullPointerException e) {
            // some tests don't have a Context
            sdk = Build.VERSION.SDK_INT;
        }
        if (mode == MODE_CALL_SCREENING && sdk <= Build.VERSION_CODES.Q) {
            mode = MODE_IN_CALL;
        }
        return mode;
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}

Click here For more examples