Question

I'm writing app that should play sound notification even in silent mode. I don't want to temporarily turn off Silent and roll it back late. I'm using ALARM stream for that now. Usually it works proper, because by default ALARM stream not muted in silent. But sometimes it is.

How can I understand if stream currently muted (in silent mode)? How can I unmute it (without switching to normal mode)?

Was it helpful?

Solution

Answering my own question:

The solution was found in Android OS sources (in standard Alarm app).

I had found way to check and set option "Alarm in Silent":

private static final int ALARM_STREAM_TYPE_BIT =
        1 << AudioManager.STREAM_ALARM;

public static void setAlarmInSilent(boolean on) {
    int ringerModeStreamTypes = Settings.System.getInt(
            context.getContentResolver(),
            Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0);

    if (on) {
        ringerModeStreamTypes &= ~ALARM_STREAM_TYPE_BIT;
    } else {
        ringerModeStreamTypes |= ALARM_STREAM_TYPE_BIT;
    }

    Settings.System.putInt(context.getContentResolver(),
            Settings.System.MODE_RINGER_STREAMS_AFFECTED,
            ringerModeStreamTypes );
}

Link to the Android src: https://android.googlesource.com/platform/packages/apps/AlarmClock/+/donut-release2/src/com/android/alarmclock/SettingsActivity.java

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top