How can I toggle these switches programmatically? I have tried various things such as :
private void allowAlarms() {
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
assert notificationManager != null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
notificationManager.setNotificationPolicy(
new NotificationManager.Policy(NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS,
NotificationManager.Policy.PRIORITY_SENDERS_ANY,
NotificationManager.Policy.PRIORITY_SENDERS_ANY));
}
notificationManager.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_PRIORITY);
}
and even simply unmuting the phone:
private void allowAlarms() {
final AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
assert am != null;
am.adjustVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_UNMUTE);
System.out.println("Alarms ON");
}
Nothing works, meaning that the alarm sound doesn't get toggled on/turned on. Thanks for any help!
Edit: just to confirm that ACTION_NOTIFICATION_POLICY_ACCESS_GRANTED is true.
One more question: if I looked into Google source code to identify how they do it, any ideas roughly where to look?