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.
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.