I have an app that mutes the phone by using AudioManager and setting ringer mode to silent with this code:
AudioManager audioManager =
(AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
try {
audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT)
} catch (Exception e) {
e.printStackTrace();
}
This works with Android 6, but now with Android 7, I get the following error:
System.err: java.lang.SecurityException: Not allowed to change Do Not Disturb state
System.err: at android.os.Parcel.readException(Parcel.java:1683)
System.err: at android.os.Parcel.readException(Parcel.java:1636)
System.err: at android.media.IAudioService$Stub$Proxy.setRingerModeExternal(IAudioService.java:962)
System.err: at android.media.AudioManager.setRingerMode(AudioManager.java:1022)
System.err: at controllers.SearchResultController.mutePhone(SearchResultController.java:185)
Are there any new permissions I need to ask for to make this work?
I looked through the Android permissions list, but couldn't find any that seemed relevant.