'Why my app switches to normal ringtone mode but doesn't play the ringtone?

When i traid to set the RINGER_MODE_NORMAL the application changes but does not sound, it changes the icon at the top of the screen but it does not make any sound. The idea is that it switches to normal sound mode when a call is coming in.

class PhoneStateListenerClass @Inject constructor(
       @ApplicationContext context: Context,): PhoneStateListener() {
val audiomanager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
 override fun onCallStateChanged(state: Int, incomingNumber: String) {
    if(state==TelephonyManager.CALL_STATE_RINGING){
        audiomanager.ringerMode=AudioManager.RINGER_MODE_NORMAL //change the icon but dont sound the ringtone
    }
    if (state==TelephonyManager.CALL_STATE_IDLE){
       audiomanager.ringerMode=AudioManager.RINGER_MODE_VIBRATE
    }
    super.onCallStateChanged(state, incomingNumber)
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source