Xanatos
Xanatos

Reputation: 1626

How can I access the audio 'Priority Mode' on a device running Android 5.0?

Android 5.0 includes a new way to control which apps are allowed to make noise on your device: when you press the volume button, the popup now lets you to choose None (completely silent), Priority (only priority notifications make sound), or All (everything is allowed to make noise.)

New 'priority mode' controls in Android 5.0

I would like my app to be able to query the device to find out which of these three modes is currently active, and also I would like to be able to change these modes (without requiring the device to be rooted). Does anyone know how to do this?

So far, all I can find is a brief reference on this changelog:

Setting the device to RINGER_MODE_SILENT causes the device to enter the new priority mode. The device leaves priority mode if you set it to RINGER_MODE_NORMAL or RINGER_MODE_VIBRATE.

This works as described, which allows me a very limited ability to change "priority mode" by modifying the ringer mode in AudioManager. That's not enough, though, as I need to be able to know exactly which of the three priority mode settings is currently active, and it would also be nice if I could change them more precisely than AudioManager allows.

Upvotes: 6

Views: 4337

Answers (1)

henrichg
henrichg

Reputation: 301

I've found a solution, but this requires root to change, because this setting is in Settings.Global.

Name of setting is "zen_mode".

Values are:

ZENMODE_ALL = 0;
ZENMODE_PRIORITY = 1;
ZENMODE_NONE = 2;

EDIT: I've found another solution. Check NotificationListenerService.requestInterruptionFilter(int interruptionFilter). https://developer.android.com/reference/android/service/notification/NotificationListenerService.html Implementation example: https://github.com/kpbird/NotificationListenerService-Example

Upvotes: 8

Related Questions