简体   繁体   English

Android 如何完全静音流语音通话?

[英]Android how can I mute stream voice call compeletely?

As the title suggests, I want to mute the sound before the call was connected.正如标题所暗示的那样,我想在呼叫接通之前将声音静音。 I set stream by below code:我通过以下代码设置流:

mAudioManager.setStreamMute(AudioManager.STREAM_VOICE_CALL, true);

and also try code:并尝试代码:

mAudioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, 0, 0);

It can make the sound at the lowest, but it is not silent.它可以使声音最低,但它并不安静。 There is still a small sound.还是有很小的声音。 If I play another music this time, they will mix together.如果我这次播放其他音乐,它们会混合在一起。 I don't want this suitation.我不想要这个套装。

Do any one have any ideas to avoid this issue?有没有人有任何想法可以避免这个问题? Many thanks.非常感谢。

Here you go:干得好:

val audioManager = getSystemService(AudioManager::class.java)
audioManager.mode = AudioManager.MODE_IN_CALL
audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL,
        AudioManager.FLAG_SHOW_UI, 0)
audioManager.adjustStreamVolume(AudioManager.STREAM_VOICE_CALL,
        AudioManager.ADJUST_TOGGLE_MUTE, 0)
audioManager.adjustVolume(AudioManager.ADJUST_MUTE, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE)

I think This code from my mp3 player should help u to solve the issue.我认为来自我的 mp3 播放器的这段代码应该可以帮助你解决这个问题。

phoneStateListener = new PhoneStateListener() {
            @Override
            public void onCallStateChanged(int state, String incomingNumber) {
                // String stateString = "N/A";

                Log.v(TAG, "Starting CallStateChange");
                switch (state) {

                case TelephonyManager.CALL_STATE_OFFHOOK:

                case TelephonyManager.CALL_STATE_RINGING:
                    if (mp != null) {
                        mp.pause();;        
                        isPausedInCall = true;

                    }

                    break;

                case TelephonyManager.CALL_STATE_IDLE:
                    // Phone idle. Start playing.

                    if (mp != null) {
                        if (isPausedInCall) {
                            isPausedInCall = false;
                            initNotification();
                            mp.start();
                        }

                    }

                    break;
                }

            }
        };

        // Register the listener with the telephony manager
        telephonyManager.listen(phoneStateListener,
                PhoneStateListener.LISTEN_CALL_STATE);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM