MODE_IN_CALL、MODE_IN_COMMUNICATION MODE_CALL_SCREENING有什么区别?

What is the differences between MODE_IN_CALL, MODE_IN_COMMUNICATION, MODE_CALL_SCREENING?

提问人:c-an 提问时间:10/21/2021 最后编辑:Haddadc-an 更新时间:3/23/2022 访问量:2734

问:

这就是文件所说的,但我不能完全理解。

/* 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;

你能举例说明一下吗?

目前,我在 WebView 上使用视频聊天服务,我得到,它使用媒体音量,它应该使用“通话”音量。我怎样才能强迫它?MODE_CALL_SCREENING

安卓 android-audiomanager android-audio-streams

评论


答:

1赞 user16930239 1/10/2022 #1

MODE_IN_CALL
您正在通过纯音频通话(普通电话)与某人交谈


MODE_IN_COMMUNICATION,您正在与朋友进行视频和音频聊天或在VoIP上呼叫他们

MODE_CALL_SCREENING
您的电话响了,并且您在接听电话之前正在检查号码

评论

0赞 c-an 1/17/2022
你能举几个例子吗?
0赞 I_Al-thamary 1/17/2022 #2

mode 参数在 AudioSystem 类中定义,用于设置手机的状态

MODE_IN_CALL:来电模式。电话呼叫已建立。

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);
  }
}

另一个例子

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:在通信音频模式下。建立音频/视频聊天或 VoIP 通信。

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:正在进行呼叫筛选。已接通呼叫,但音频未使用。 呼叫筛选:这是识别来电者、提供有关来电者的信息以及确定如何最好地响应该呼叫的过程。

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();
    }
}

点击这里查看更多例子

评论

0赞 blade 3/22/2022
您能否解释何时使用哪个以及为什么使用?使用一个比另一个有什么好处?
0赞 I_Al-thamary 3/22/2022
如果你阅读了答案,你会发现我在答案中解释了它们。
1赞 blade 3/23/2022
我读了你的答案,它很有用,但你没有解释为什么使用一个而不是另一个。这些标志的效果/好处是什么?例如,我在应用程序中将MODE_IN_COMMUNICATION替换为MODE_IN_CALL,会有什么变化?用户将受到什么影响?
0赞 I_Al-thamary 3/23/2022
MODE_IN_CALL: 电话 : 音频/视频聊天或VoIP通信 :识别来电者,提供有关来电者的信息,并确定如何最好地响应该呼叫MODE_IN_COMMUNICATIONMODE_CALL_SCREENING