Android how can I mute stream voice call compeletely?

3.8k views Asked by At

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.

2

There are 2 answers

1
JaKoZo On

I think This code from my mp3 player should help u to solve the issue.

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);
0
Arsenius On

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)