Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2a2886fd authored by Michael Potter's avatar Michael Potter Committed by Gitsaibot
Browse files

create notification channels before using (#574)

parent 1af871e0
Loading
Loading
Loading
Loading
+1 −18
Original line number Diff line number Diff line
@@ -263,24 +263,7 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH
        mController = CalendarController.getInstance(this);

        // Create notification channel
        NotificationMgr nm = new AlertService.NotificationMgrWrapper(
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE));
        if (Utils.isOreoOrLater()) {
            NotificationChannel channel  = new NotificationChannel(
                    ALERT_CHANNEL_ID,
                    this.getString(R.string.standalone_app_label),
                    NotificationManager.IMPORTANCE_HIGH);

            NotificationChannel foregroundChannel = new NotificationChannel(
                    FOREGROUND_CHANNEL_ID,
                    this.getString(R.string.foreground_notification_channel_name),
                    NotificationManager.IMPORTANCE_LOW);
            foregroundChannel.setDescription(
                    this.getString(R.string.foreground_notification_channel_description));

            nm.createNotificationChannel(channel);
            nm.createNotificationChannel(foregroundChannel);
        }
        AlertService.createChannels(this);

        // Check and ask for most needed permissions
        checkAppPermissions();
+25 −0
Original line number Diff line number Diff line
@@ -984,6 +984,8 @@ public class AlertService extends Service {
        if (intent != null) {

            if (Utils.isOreoOrLater()) {

                createChannels(this);
                Notification notification = new NotificationCompat.Builder(this, FOREGROUND_CHANNEL_ID)
                        .setContentTitle("Event notifications")
                        .setSmallIcon(R.drawable.stat_notify_calendar)
@@ -1010,6 +1012,29 @@ public class AlertService extends Service {
        return null;
    }

    public static void createChannels(Context context) {
        if (Utils.isOreoOrLater()) {
            // Create notification channel
            NotificationMgr nm = new NotificationMgrWrapper(
                    (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE));

            NotificationChannel channel  = new NotificationChannel(
                    ALERT_CHANNEL_ID,
                    context.getString(R.string.standalone_app_label),
                    NotificationManager.IMPORTANCE_HIGH);

            NotificationChannel foregroundChannel = new NotificationChannel(
                    FOREGROUND_CHANNEL_ID,
                    context.getString(R.string.foreground_notification_channel_name),
                    NotificationManager.IMPORTANCE_LOW);
            foregroundChannel.setDescription(
                    context.getString(R.string.foreground_notification_channel_description));

            nm.createNotificationChannel(channel);
            nm.createNotificationChannel(foregroundChannel);
        }
    }

    // Added wrapper for testing
    public static class NotificationWrapper {
        Notification mNotification;