Example usage for android.app NotificationManager IMPORTANCE_LOW

List of usage examples for android.app NotificationManager IMPORTANCE_LOW

Introduction

In this page you can find the example usage for android.app NotificationManager IMPORTANCE_LOW.

Prototype

int IMPORTANCE_LOW

To view the source code for android.app NotificationManager IMPORTANCE_LOW.

Click Source Link

Document

Low notification importance: shows everywhere, but is not intrusive.

Usage

From source file:com.z3r0byte.magistify.Services.BackgroundService.java

private void newHomeworkNotification() {
    Appointment[] newhomework = homeworkDB.getAppointmentsWithHomework();
    ArrayList<Appointment> homeworkList = new ArrayList<>();
    for (Appointment appointment : newhomework) {
        if (homeworkDB.isModified(appointment, true))
            homeworkList.add(appointment);
    }/*from  w  ww. ja  v a2 s  .  c  o  m*/
    Log.d(TAG, "newHomeworkNotification: Amount of new homework: " + homeworkList.size());
    if (homeworkList.size() > 0) {
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
        mBuilder.setSmallIcon(R.drawable.ic_new_homework);

        String content = "Je hebt nieuw of aangepast huiswerk voor:";
        for (Appointment appointment : homeworkList) {
            content = content + "\n" + appointment.description
                    + DateUtils.formatDate(appointment.startDate, "' ('dd MMM')'");
        }

        mBuilder.setContentTitle("Nieuw huiswerk");
        mBuilder.setStyle(new NotificationCompat.BigTextStyle(mBuilder).bigText(content));
        mBuilder.setContentText(content);
        mBuilder.setAutoCancel(true);
        mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
        mBuilder.setDefaults(Notification.DEFAULT_ALL);

        Intent resultIntent = new Intent(context, HomeworkActivity.class);
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addParentStack(ScheduleChangeActivity.class);
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(resultPendingIntent);

        NotificationManager mNotificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        if (Build.VERSION.SDK_INT >= 26) {
            String channelId = NEW_HOMEWORK_NOTIFICATIONCHANNEL_ID;
            CharSequence channelName = NEW_HOMEWORK_NOTIFICATIONCHANNEL_ID;
            int importance = NotificationManager.IMPORTANCE_LOW;
            NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName,
                    importance);
            notificationChannel.enableLights(true);
            notificationChannel.setLightColor(Color.RED);
            notificationChannel.enableVibration(true);
            notificationChannel.setImportance(NotificationManager.IMPORTANCE_DEFAULT);
            notificationChannel.setVibrationPattern(new long[] { 100, 200, 150 });
            mNotificationManager.createNotificationChannel(notificationChannel);
            mBuilder.setChannelId(NEW_HOMEWORK_NOTIFICATIONCHANNEL_ID);
        }
        mNotificationManager.notify(NEW_HOMEWORK_NOTIFICATION_ID, mBuilder.build());
    }
}

From source file:com.z3r0byte.magistify.Services.BackgroundService.java

private void unFinishedHomeworkNotification() {
    String lastCheck = configUtil.getString("last_unfinished_homework_check");
    if (lastCheck.equals(""))
        lastCheck = DateUtils.formatDate(DateUtils.addDays(new Date(), -1), "yyyyMMdd");

    Date lastCheckDate = DateUtils.parseDate(lastCheck, "yyyyMMdd");
    Date now = DateUtils.parseDate(DateUtils.formatDate(new Date(), "yyyyMMdd"), "yyyyMMdd");
    Integer hours = configUtil.getInteger("unfinished_homework_hour");
    Integer minutes = configUtil.getInteger("unfinished_homework_minute");
    if (lastCheckDate.before(now)) {
        lastCheckDate = DateUtils.addHours(lastCheckDate, 24 + hours);
        lastCheckDate = DateUtils.addMinutes(lastCheckDate, minutes);
        if (new Date().after(lastCheckDate)) {
            Appointment[] appointments = calendarDB.getUnfinishedAppointments(DateUtils.addDays(now, 1));

            if (appointments.length > 0) {

                NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
                mBuilder.setSmallIcon(R.drawable.ic_unfinished_homework);
                mBuilder.setContentTitle("Huiswerk waarschuwing");

                if (appointments.length == 1) {
                    mBuilder.setContentText(appointments[0].description);
                } else {
                    String content = "Je hebt je huiswerk voor de volgende lessen van morgen nog niet afgerond:";
                    for (Appointment appointment : appointments) {
                        String string = appointment.description;
                        if (content.length() > 1) {
                            content = content + "\n" + string;
                        } else {
                            content = string;
                        }/*from w  w  w  .  ja v  a 2 s. c  o  m*/
                    }
                    mBuilder.setStyle(new NotificationCompat.BigTextStyle(mBuilder).bigText(content));
                    mBuilder.setContentText(content);
                }
                mBuilder.setAutoCancel(true);
                mBuilder.setVisibility(NotificationCompat.VISIBILITY_PRIVATE);
                mBuilder.setDefaults(Notification.DEFAULT_ALL);
                mBuilder.setLights(Color.RED, 300, 200);

                Intent resultIntent = new Intent(context, HomeworkActivity.class);
                TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
                stackBuilder.addParentStack(NewGradeActivity.class);
                stackBuilder.addNextIntent(resultIntent);
                PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                        PendingIntent.FLAG_UPDATE_CURRENT);
                mBuilder.setContentIntent(resultPendingIntent);

                NotificationManager mNotificationManager = (NotificationManager) context
                        .getSystemService(Context.NOTIFICATION_SERVICE);
                if (Build.VERSION.SDK_INT >= 26) {
                    String channelId = UNFINISHED_HOMEWORK_NOTIFICATIONCHANNEL_ID;
                    CharSequence channelName = UNFINISHED_HOMEWORK_NOTIFICATIONCHANNEL_ID;
                    int importance = NotificationManager.IMPORTANCE_LOW;
                    NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName,
                            importance);
                    notificationChannel.enableLights(true);
                    notificationChannel.setLightColor(Color.RED);
                    notificationChannel.enableVibration(true);
                    notificationChannel.setImportance(NotificationManager.IMPORTANCE_DEFAULT);
                    notificationChannel.setVibrationPattern(new long[] { 100, 200, 150 });
                    mNotificationManager.createNotificationChannel(notificationChannel);
                    mBuilder.setChannelId(UNFINISHED_HOMEWORK_NOTIFICATIONCHANNEL_ID);
                }
                mNotificationManager.notify(UNFINISHED_HOMEWORK_NOTIFICATION_ID, mBuilder.build());
            }

            configUtil.setString("last_unfinished_homework_check",
                    DateUtils.formatDate(new Date(), "yyyyMMdd"));
        }
    }
}

From source file:org.restcomm.android.sdk.RCDevice.java

/**
 * Method returns the Notification builder
 * For Oreo devices we can have channels with HIGH and LOW importance.
 * If highImportance is true builder will be created with HIGH priority
 * For pre Oreo devices builder without channel will be returned
 * @param highImportance true if we need HIGH channel, false if we need LOW
 * @return/*from   w ww  .  ja va 2  s  . com*/
 */
private NotificationCompat.Builder getNotificationBuilder(boolean highImportance) {
    NotificationCompat.Builder builder;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        if (highImportance) {
            NotificationChannel channel = new NotificationChannel(PRIMARY_CHANNEL_ID, PRIMARY_CHANNEL,
                    NotificationManager.IMPORTANCE_HIGH);
            channel.setLightColor(Color.GREEN);
            channel.enableLights(true);
            channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
            channel.enableVibration(true);
            channel.setVibrationPattern(notificationVibrationPattern);

            ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE))
                    .createNotificationChannel(channel);
            builder = new NotificationCompat.Builder(RCDevice.this, PRIMARY_CHANNEL_ID);
        } else {
            NotificationManager notificationManager = (NotificationManager) getSystemService(
                    Context.NOTIFICATION_SERVICE);
            NotificationChannel notificationChannel = new NotificationChannel(DEFAULT_FOREGROUND_CHANNEL_ID,
                    DEFAULT_FOREGROUND_CHANNEL, NotificationManager.IMPORTANCE_LOW);
            notificationManager.createNotificationChannel(notificationChannel);

            builder = new NotificationCompat.Builder(RCDevice.this, DEFAULT_FOREGROUND_CHANNEL_ID);
        }

    } else {
        builder = new NotificationCompat.Builder(RCDevice.this);
    }

    return builder;
}