diff --git a/app/src/main/java/com/jens/automation2/Actions.java b/app/src/main/java/com/jens/automation2/Actions.java index 6ed43ee9..59040c1e 100644 --- a/app/src/main/java/com/jens/automation2/Actions.java +++ b/app/src/main/java/com/jens/automation2/Actions.java @@ -781,6 +781,23 @@ public class Actions return false; } + public static void setDoNotDisturb(Context context, int desiredDndMode) + { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) + { + /* + if (!notificationManager.isNotificationPolicyAccessGranted()) + --> done externally + */ + + Miscellaneous.logEvent("i", context.getResources().getString(R.string.soundSettings), "Changing DND to " + String.valueOf(desiredDndMode), 4); + NotificationManager mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); + mNotificationManager.setInterruptionFilter(desiredDndMode); + } + else + Miscellaneous.logEvent("w", context.getResources().getString(R.string.soundSettings), "Cannot change DND to " + String.valueOf(desiredDndMode) + ". This Android version is too and doesn\'t have that feature, yet.", 4); + } + @RequiresApi(api = Build.VERSION_CODES.M) public static boolean isDoNotDisturbActive(Context context) { @@ -915,18 +932,6 @@ public class Actions } } - public static void setDND(Context context, int desiredDndMode) - { - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) - { - Miscellaneous.logEvent("i", context.getResources().getString(R.string.soundSettings), "Changing DND to " + String.valueOf(desiredDndMode), 4); - NotificationManager mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); - mNotificationManager.setInterruptionFilter(desiredDndMode); - } - else - Miscellaneous.logEvent("w", context.getResources().getString(R.string.soundSettings), "Cannot change DND to " + String.valueOf(desiredDndMode) + ". This Android version is too and doesn\'t have that feature, yet.", 4); - } - public void useDownloadedWebpage(String result) { // Toast.makeText(context, "Result: " + result, Toast.LENGTH_LONG).show(); diff --git a/app/src/main/java/com/jens/automation2/Profile.java b/app/src/main/java/com/jens/automation2/Profile.java index 5f40373e..d1241e31 100644 --- a/app/src/main/java/com/jens/automation2/Profile.java +++ b/app/src/main/java/com/jens/automation2/Profile.java @@ -4,12 +4,10 @@ import android.app.NotificationManager; import android.content.ContentValues; import android.content.Context; import android.media.AudioManager; -import android.media.Ringtone; import android.media.RingtoneManager; import android.net.Uri; import android.os.Build; import android.provider.MediaStore; -import android.provider.Settings; import android.util.Log; import android.widget.Toast; @@ -509,7 +507,7 @@ public class Profile implements Comparable Actions.setSound(context, soundMode); if(changeDndMode) - Actions.setDND(context, dndMode); + Actions.setDoNotDisturb(context, dndMode); if(changeVolumeMusicVideoGameMedia) am.setStreamVolume(AudioManager.STREAM_MUSIC, volumeMusic, AudioManager.FLAG_PLAY_SOUND);