Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 218
Xanatos Avatar asked Nov 10 '14 18:11

Xanatos


People also ask

What is priority only on Android?

The latest Android 13 developer beta introduced a new moniker to the Android world: Priority Mode. This is a renaming of a well-known feature in Android 12. The idea behind Priority Mode is for you to take some time out from your phone in everyday life.

What is audio focus denied?

A media or game app that uses audio focus shouldn't play audio after it loses focus. In Android 12 (API level 31) and higher, the system enforces this behavior. When an app requests audio focus while another app has the focus and is playing, the system forces the playing app to fade out.


1 Answers

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

like image 177
henrichg Avatar answered Oct 06 '22 00:10

henrichg