So I'm trying to wrap my head around Audio Attributes. Here's what I have so far:
// alarm.getSound() will return a proper URI to pick a ringtone
Ringtone tone = RingtoneManager.getRingtone(this, alarm.getSound());
if (Build.VERSION.SDK_INT >= 21) {
AudioAttributes aa = new AudioAttributes.Builder()
.setFlags(AudioAttributes.USAGE_ALARM | AudioAttributes.CONTENT_TYPE_SONIFICATION)
.build();
tone.setAudioAttributes(aa);
} else {
tone.setStreamType(RingtoneManager.TYPE_ALARM);
}
tone.play();
This page talks about Audio Attributes and their "Compatibility Mappings." If I was previously using setStreamType(TYPE_ALARM)
(like I am above) then it will set the CONTENT_TYPE_SONIFICATION
and USAGE_ALARM
flags. I want to get away from setStreamType
so I was thinking that if I manually set those flags (like I am above) then when the ringtone plays it will use the Alarm volume. Well, it doesn't seem to work like that.
The above code still rings using my Nexus 6's Media volume instead of the Alarm volume. I'm on 6.0 with build MRA68N. What could I do different to use the Alarm volume?