0

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:

  1. android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS
  2. multiple mutes require multiple unmutes

Any help?

anothermh
  • 9,815
  • 3
  • 33
  • 52
emk
  • 1
  • https://stackoverflow.com/questions/23589561/programatically-disable-all-sound-and-vibration-in-android check this link – reinhard.lee Oct 17 '17 at 02:11
  • Thanks. The link you provide demonstrates that the problem exists and offers a workaround. It seems to me that there is a bug in AudioManager if there are no additional steps or context I can provide that will result in audioManager.isStreamMute(STREAM_ALARM) returning true after a seemingly successful call to audioManager.adjustStreamVolume( STREAM_ALARM, AudioManager.ADJUST_MUTE, 0) – emk Oct 20 '17 at 12:42
  • I just verified in Android 8.0 that if I use Google's "Do Not Disturb" feature and select Total Silence that isStreamMute(STREAM_ALARM) returns true. – emk Oct 20 '17 at 12:56
  • Responding to my own comment that there is an Android bug here. It turns out that using the strategy specified in the stackoverflow reference results in isStreamMute(STREAM_ALARM) returning true. So my remark about 'no additional steps' is thus made void. I still think there is a bug in that the documented API works differently for STREAM_ALARM than for the sibling streams, and that this may be due to an underlying implementation bug. – emk Oct 20 '17 at 17:45

0 Answers0