androidandroid-6.0-marshmallowringincoming-call

In Android M, changing the ringer mode while the incoming call is ringing doesn't have any effect


I made an app a while ago that changes the ring mode whenever certain paople call. So, when one of those people call, it changes the ring mode to make the call ring at full volume. I use

setRingerMode(AudioManager.RINGER_MODE_NORMAL)
am.setStreamVolume(AudioManager.STREAM_RING, am.getStreamMaxVolume(AudioManager.STREAM_RING), 0);

The app also changes the interrupt filter to INTERRUPTION_FILTER_ALL, but to make things easier, let's assume that Do Not Disturb isn't enabled. So, for example, if the phone was set to vibrate, when there is an incoming call from a matching contact, it switches the ringer on, and sets the volume to max.

Everything worked fine before I got a phone with Marshmallow (Nexus 6P). Now, if there is an incoming call, my app changes the ring mode and volume as usual, but the incoming call doesn't get affected. It still behaves the same way, even thought the ringer settings got changed. I can verify that my app is defnintely making the changes -- after the call is finished, the ring volume settings are exactly as they should be. And if another call comes in, that one rings properly. It just seems like the ring mode changes aren't being applied to an incoming call that's already in progress.

Does anyone have anu suggestions as to what's changes in Marshmallow that's causing this, and if there is a way around it?


Solution

  • So, I found a way around this. I still have no idea how to fix this bug (or why it exists in the first place), but my workaround works pretty well. In addition to telling the OS to change the ring mode, I'm manually retrieving the default ringtone, and playing it in the app when a call comes in:

    Uri alertUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
    Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), alertUri);
    if(r != null && !r.isPlaying()){
        r.play();
    }
    

    And then, when the incoming call stops ringing, I manually stop that Ringtone.