我在Kotlin的API 23下运行此代码:
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
STREAM_MUSIC,STREAM_NOTIFICATION,STREAM_RING一切正常。
但是,STREAM_ALARM拒绝将状态从静音状态更改为非静音状态或vv。
有些问题不是问题:
任何帮助?