I have this code running under API 23 in Kotlin:
fun handleStreamButton(id: Int, streamID: Int) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
debugOut("handleStreamButton(): Build.VERSION.SDK_INT >= Build.VERSION_CODES.M")
} else {
debugOut("handleStreamButton(): Build.VERSION.SDK_INT < Build.VERSION_CODES.M")
}
var tb: ToggleButton = getToggleButton(id)
var toMute = getToggleButtonState(tb)
var muteAction = AudioManager.ADJUST_UNMUTE
if (toMute) {
muteAction = AudioManager.ADJUST_MUTE
}
var before = audioManager.isStreamMute(streamID);
audioManager.adjustStreamVolume(
streamID,
muteAction,
0)
/*
* deprecated, but worth a try. No joy.
audioManager.setStreamMute(streamID, toMute)
*/
var after = audioManager.isStreamMute(streamID);
debugOut("handleStreamButton(): before: " + before + "; after: " + after)
} // handleStreamButton
Everything works as expected for STREAM_MUSIC, STREAM_NOTIFICATION, STREAM_RING.
However, STREAM_ALARM refuses to change state either from muted to unmuted or vv.
Several things that are not the problem:
- android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS
- multiple mutes require multiple unmutes
Any help?