In Android 7 (API level 24) my app is not allowed to mute phone (set ringer mode to silent)
问题 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