Example usage for android.support.v4.app NotificationManagerCompat from

List of usage examples for android.support.v4.app NotificationManagerCompat from

Introduction

In this page you can find the example usage for android.support.v4.app NotificationManagerCompat from.

Prototype

public static NotificationManagerCompat from(Context context) 

Source Link

Usage

From source file:net.kenevans.android.hxmmonitor.HxMBleService.java

@Override
public void onCreate() {
    super.onCreate();
    // Post a notification the service is running
    Intent activityIntent = new Intent(this, DeviceMonitorActivity.class);
    PendingIntent viewPendingIntent = PendingIntent.getActivity(this, 0, activityIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.hxmmonitor).setContentTitle(getString(R.string.service_notification_title))
            .setContentText(getString(R.string.service_notification_text)).setContentIntent(viewPendingIntent);
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
}

From source file:com.daiv.android.twitter.utils.NotificationUtils.java

public static void refreshNotification(Context context, boolean noTimeline) {
    AppSettings settings = AppSettings.getInstance(context);

    SharedPreferences sharedPrefs = context.getSharedPreferences("com.daiv.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);
    int currentAccount = sharedPrefs.getInt("current_account", 1);

    //int[] unreadCounts = new int[] {4, 1, 2}; // for testing
    int[] unreadCounts = getUnreads(context);

    int timeline = unreadCounts[0];
    int realTimelineCount = timeline;

    // if they don't want that type of notification, simply set it to zero
    if (!settings.timelineNot || (settings.pushNotifications && settings.liveStreaming) || noTimeline) {
        unreadCounts[0] = 0;// w  w  w  .  ja  v  a 2s .c  o  m
    }
    if (!settings.mentionsNot) {
        unreadCounts[1] = 0;
    }
    if (!settings.dmsNot) {
        unreadCounts[2] = 0;
    }

    if (unreadCounts[0] == 0 && unreadCounts[1] == 0 && unreadCounts[2] == 0) {

    } else {
        Intent markRead = new Intent(context, MarkReadService.class);
        PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0);

        String shortText = getShortText(unreadCounts, context, currentAccount);
        String longText = getLongText(unreadCounts, context, currentAccount);
        // [0] is the full title and [1] is the screenname
        String[] title = getTitle(unreadCounts, context, currentAccount);
        boolean useExpanded = useExp(context);
        boolean addButton = addBtn(unreadCounts);

        if (title == null) {
            return;
        }

        Intent resultIntent;

        if (unreadCounts[1] != 0 && unreadCounts[0] == 0) {
            // it is a mention notification (could also have a direct message)
            resultIntent = new Intent(context, RedirectToMentions.class);
        } else {
            resultIntent = new Intent(context, MaterialMainActivity.class);
        }

        PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);

        NotificationCompat.Builder mBuilder;

        Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class);

        mBuilder = new NotificationCompat.Builder(context).setContentTitle(title[0])
                .setContentText(TweetLinkUtils.removeColorHtml(shortText, settings))
                .setSmallIcon(R.drawable.ic_stat_icon).setLargeIcon(getIcon(context, unreadCounts, title[1]))
                .setContentIntent(resultPendingIntent).setAutoCancel(true)
                .setTicker(TweetLinkUtils.removeColorHtml(shortText, settings))
                .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0))
                .setPriority(NotificationCompat.PRIORITY_HIGH);

        if (unreadCounts[1] > 1 && unreadCounts[0] == 0 && unreadCounts[2] == 0) {
            // inbox style notification for mentions
            mBuilder.setStyle(getMentionsInboxStyle(unreadCounts[1], currentAccount, context,
                    TweetLinkUtils.removeColorHtml(shortText, settings)));
        } else if (unreadCounts[2] > 1 && unreadCounts[0] == 0 && unreadCounts[1] == 0) {
            // inbox style notification for direct messages
            mBuilder.setStyle(getDMInboxStyle(unreadCounts[1], currentAccount, context,
                    TweetLinkUtils.removeColorHtml(shortText, settings)));
        } else {
            // big text style for an unread count on timeline, mentions, and direct messages
            mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml(
                    settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText)));
        }

        // Pebble notification
        if (sharedPrefs.getBoolean("pebble_notification", false)) {
            sendAlertToPebble(context, title[0], shortText);
        }

        // Light Flow notification
        sendToLightFlow(context, title[0], shortText);

        int homeTweets = unreadCounts[0];
        int mentionsTweets = unreadCounts[1];
        int dmTweets = unreadCounts[2];

        int newC = 0;

        if (homeTweets > 0) {
            newC++;
        }
        if (mentionsTweets > 0) {
            newC++;
        }
        if (dmTweets > 0) {
            newC++;
        }

        if (settings.notifications && newC > 0) {

            if (settings.vibrate) {
                mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
            }

            if (settings.sound) {
                try {
                    mBuilder.setSound(Uri.parse(settings.ringtone));
                } catch (Exception e) {
                    mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
                }
            }

            if (settings.led)
                mBuilder.setLights(0xFFFFFF, 1000, 1000);

            // Get an instance of the NotificationManager service
            NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);

            if (addButton) { // the reply and read button should be shown

                Log.v("username_for_noti", title[1]);
                sharedPrefs.edit().putString("from_notification", "@" + title[1] + " " + title[2]).commit();
                MentionsDataSource data = MentionsDataSource.getInstance(context);
                long id = data.getLastIds(currentAccount)[0];
                PendingIntent replyPending = PendingIntent.getActivity(context, 0, null, 0);
                sharedPrefs.edit().putLong("from_notification_long", id).commit();
                sharedPrefs.edit()
                        .putString("from_notification_text",
                                "@" + title[1] + ": " + TweetLinkUtils.removeColorHtml(shortText, settings))
                        .commit();

                // Create the remote input
                RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY)
                        .setLabel("@" + title[1] + " ").build();

                // Create the notification action
                NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(
                        R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply),
                        replyPending).addRemoteInput(remoteInput).build();

                NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder(
                        R.drawable.ic_action_read_dark, context.getResources().getString(R.string.mark_read),
                        readPending);

                mBuilder.addAction(replyAction);
                mBuilder.addAction(action.build());
            }

            // Build the notification and issues it with notification manager.
            notificationManager.notify(1, mBuilder.build());

            // if we want to wake the screen on a new message
            if (settings.wakeScreen) {
                PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
                final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK
                        | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
                wakeLock.acquire(5000);
            }
        }

        // if there are unread tweets on the timeline, check them for favorite users
        if (settings.favoriteUserNotifications && realTimelineCount > 0) {
            favUsersNotification(currentAccount, context);
        }
    }

    try {

        ContentValues cv = new ContentValues();

        cv.put("tag", "com.daiv.android.twitter/com.daiv.android.twitter.ui.MainActivity");

        // add the direct messages and mentions
        cv.put("count", unreadCounts[1] + unreadCounts[2]);

        context.getContentResolver().insert(Uri.parse("content://com.teslacoilsw.notifier/unread_count"), cv);

    } catch (IllegalArgumentException ex) {

        /* Fine, TeslaUnread is not installed. */

    } catch (Exception ex) {

        /* Some other error, possibly because the format
           of the ContentValues are incorrect.
                
        Log but do not crash over this. */

        ex.printStackTrace();

    }
}

From source file:com.kubotaku.android.code4kyoto5374.util.AlarmService.java

private void handleActionNotify(final int garbageType) {
    String garbageText = "";
    switch (garbageType) {
    case GarbageType.TYPE_BURNABLE:
    case GarbageType.TYPE_BIN:
    case GarbageType.TYPE_PLASTIC:
    case GarbageType.TYPE_SMALL:
        garbageText = GarbageType.getViewText(garbageType);
        break;/*from w  ww  .ja  v a  2 s .  c  om*/

    default:
        return; // ???????
    }

    final Notification notification = new NotificationCompat.Builder(this).setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle(garbageText + "????")
            .setContentText("?8:00?????????").build();

    NotificationManagerCompat.from(this).notify(NOTIFY_ID, notification);

    // ?
    setupAlarm(this, garbageType, true);
}

From source file:com.keylesspalace.tusky.util.NotificationHelper.java

/**
 * Takes a given Mastodon notification and either creates a new Android notification or updates
 * the state of the existing notification to reflect the new interaction.
 *
 * @param context to access application preferences and services
 * @param body    a new Mastodon notification
 * @param account the account for which the notification should be shown
 *///from  ww w  .  jav  a2 s .c o m

public static void make(final Context context, Notification body, AccountEntity account,
        boolean isFirstOfBatch) {

    if (!filterNotification(account, body, context)) {
        return;
    }

    String rawCurrentNotifications = account.getActiveNotifications();
    JSONArray currentNotifications;
    BidiFormatter bidiFormatter = BidiFormatter.getInstance();

    try {
        currentNotifications = new JSONArray(rawCurrentNotifications);
    } catch (JSONException e) {
        currentNotifications = new JSONArray();
    }

    for (int i = 0; i < currentNotifications.length(); i++) {
        try {
            if (currentNotifications.getString(i).equals(body.getAccount().getName())) {
                currentNotifications.remove(i);
                break;
            }
        } catch (JSONException e) {
            Log.d(TAG, Log.getStackTraceString(e));
        }
    }

    currentNotifications.put(body.getAccount().getName());

    account.setActiveNotifications(currentNotifications.toString());

    // Notification group member
    // =========================
    final NotificationCompat.Builder builder = newNotification(context, body, account, false);

    notificationId++;

    builder.setContentTitle(titleForType(context, body, bidiFormatter)).setContentText(bodyForType(body));

    if (body.getType() == Notification.Type.MENTION) {
        builder.setStyle(new NotificationCompat.BigTextStyle().bigText(bodyForType(body)));
    }

    //load the avatar synchronously
    Bitmap accountAvatar;
    try {
        accountAvatar = Picasso.with(context).load(body.getAccount().getAvatar())
                .transform(new RoundedTransformation(20)).get();
    } catch (IOException e) {
        Log.d(TAG, "error loading account avatar", e);
        accountAvatar = BitmapFactory.decodeResource(context.getResources(), R.drawable.avatar_default);
    }

    builder.setLargeIcon(accountAvatar);

    // Reply to mention action; RemoteInput is available from KitKat Watch, but buttons are available from Nougat
    if (body.getType() == Notification.Type.MENTION
            && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        RemoteInput replyRemoteInput = new RemoteInput.Builder(KEY_REPLY)
                .setLabel(context.getString(R.string.label_quick_reply)).build();

        PendingIntent quickReplyPendingIntent = getStatusReplyIntent(REPLY_ACTION, context, body, account);

        NotificationCompat.Action quickReplyAction = new NotificationCompat.Action.Builder(
                R.drawable.ic_reply_24dp, context.getString(R.string.action_quick_reply),
                quickReplyPendingIntent).addRemoteInput(replyRemoteInput).build();

        builder.addAction(quickReplyAction);

        PendingIntent composePendingIntent = getStatusReplyIntent(COMPOSE_ACTION, context, body, account);

        NotificationCompat.Action composeAction = new NotificationCompat.Action.Builder(
                R.drawable.ic_reply_24dp, context.getString(R.string.action_compose_shortcut),
                composePendingIntent).build();

        builder.addAction(composeAction);
    }

    builder.setSubText(account.getFullName());
    builder.setVisibility(NotificationCompat.VISIBILITY_PRIVATE);
    builder.setCategory(NotificationCompat.CATEGORY_SOCIAL);
    builder.setOnlyAlertOnce(true);

    // only alert for the first notification of a batch to avoid multiple alerts at once
    if (!isFirstOfBatch) {
        builder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY);
    }

    // Summary
    // =======
    final NotificationCompat.Builder summaryBuilder = newNotification(context, body, account, true);

    if (currentNotifications.length() != 1) {
        try {
            String title = context.getString(R.string.notification_title_summary,
                    currentNotifications.length());
            String text = joinNames(context, currentNotifications, bidiFormatter);
            summaryBuilder.setContentTitle(title).setContentText(text);
        } catch (JSONException e) {
            Log.d(TAG, Log.getStackTraceString(e));
        }
    }

    summaryBuilder.setSubText(account.getFullName());
    summaryBuilder.setVisibility(NotificationCompat.VISIBILITY_PRIVATE);
    summaryBuilder.setCategory(NotificationCompat.CATEGORY_SOCIAL);
    summaryBuilder.setOnlyAlertOnce(true);
    summaryBuilder.setGroupSummary(true);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);

    //noinspection ConstantConditions
    notificationManager.notify(notificationId, builder.build());
    if (currentNotifications.length() == 1) {
        notificationManager.notify((int) account.getId(), builder.setGroupSummary(true).build());
    } else {
        notificationManager.notify((int) account.getId(), summaryBuilder.build());
    }
}

From source file:com.wizardsofm.deskclock.alarms.AlarmNotifications.java

public static void updateAlarmGroupMissedNotification(Context context) {
    if (!Utils.isNOrLater()) {
        return;//w  ww.  jav  a 2 s. c om
    }

    NotificationManagerCompat nm = NotificationManagerCompat.from(context);

    if (getActiveNotificationsCount(context, MISSED_GROUP_KEY) == 0) {
        nm.cancel(ALARM_GROUP_MISSED_NOTIFICATION_ID);
        return;
    }

    NotificationCompat.Builder summaryNotification = new NotificationCompat.Builder(context).setShowWhen(false)
            .setColor(ContextCompat.getColor(context, com.wizardsofm.deskclock.R.color.default_background))
            .setSmallIcon(com.wizardsofm.deskclock.R.drawable.stat_notify_alarm).setGroup(MISSED_GROUP_KEY)
            .setGroupSummary(true).setPriority(NotificationCompat.PRIORITY_HIGH)
            .setCategory(NotificationCompat.CATEGORY_ALARM).setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setLocalOnly(true);

    nm.notify(ALARM_GROUP_MISSED_NOTIFICATION_ID, summaryNotification.build());
}

From source file:name.gumartinm.weather.information.notification.NotificationIntentService.java

private void showNotification(final Current current, final WeatherLocation weatherLocation) {
    // 1. Update units of measurement.
    final UnitsConversor tempUnitsConversor = new TempUnitsConversor(this.getApplicationContext());

    // 2. Formatters
    final DecimalFormat tempFormatter = (DecimalFormat) NumberFormat.getNumberInstance(Locale.US);
    tempFormatter.applyPattern("###.##");

    // 3. Prepare data for RemoteViews.
    String tempMax = "";
    if (current.getMain().getTemp_max() != null) {
        double conversion = (Double) current.getMain().getTemp_max();
        conversion = tempUnitsConversor.doConversion(conversion);
        tempMax = tempFormatter.format(conversion) + tempUnitsConversor.getSymbol();
    }/*from   ww  w.  ja  va2 s  .com*/
    String tempMin = "";
    if (current.getMain().getTemp_min() != null) {
        double conversion = (Double) current.getMain().getTemp_min();
        conversion = tempUnitsConversor.doConversion(conversion);
        tempMin = tempFormatter.format(conversion) + tempUnitsConversor.getSymbol();
    }
    Bitmap picture;
    if ((current.getWeather().size() > 0) && (current.getWeather().get(0).getIcon() != null)
            && (IconsList.getIcon(current.getWeather().get(0).getIcon()) != null)) {
        final String icon = current.getWeather().get(0).getIcon();
        picture = BitmapFactory.decodeResource(this.getResources(),
                IconsList.getIcon(icon).getResourceDrawable());
    } else {
        picture = BitmapFactory.decodeResource(this.getResources(), R.drawable.weather_severe_alert);
    }
    final String city = weatherLocation.getCity();
    final String country = weatherLocation.getCountry();

    // 4. Insert data in RemoteViews.
    final RemoteViews remoteView = new RemoteViews(this.getApplicationContext().getPackageName(),
            R.layout.weather_notification);
    remoteView.setImageViewBitmap(R.id.weather_notification_image, picture);
    remoteView.setTextViewText(R.id.weather_notification_temperature_max, tempMax);
    remoteView.setTextViewText(R.id.weather_notification_temperature_min, tempMin);
    remoteView.setTextViewText(R.id.weather_notification_city, city);
    remoteView.setTextViewText(R.id.weather_notification_country, country);

    // 5. Activity launcher.
    final Intent resultIntent = new Intent(this.getApplicationContext(), MainTabsActivity.class);
    // The PendingIntent to launch our activity if the user selects this notification.
    // The stack builder object will contain an artificial back stack for the started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    final TaskStackBuilder stackBuilder = TaskStackBuilder.create(this.getApplicationContext());
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainTabsActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    final PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);

    final NotificationManagerCompat notificationManager = NotificationManagerCompat
            .from(this.getApplicationContext());

    // 6. Create notification.
    final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
            this.getApplicationContext()).setContent(remoteView).setSmallIcon(R.drawable.ic_launcher)
                    .setAutoCancel(true).setLocalOnly(true).setWhen(System.currentTimeMillis())
                    .setContentIntent(resultPendingIntent).setPriority(NotificationCompat.PRIORITY_DEFAULT);

    final Notification notification = notificationBuilder.build();
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    // Send the notification.
    // Sets an ID for the notification, so it can be updated (just in case)
    int notifyID = 1;
    notificationManager.notify(notifyID, notification);
}

From source file:org.libreoffice.impressremote.communication.DataLayerListenerService.java

private void sendLocalNotification() {
    Log.v(TAG, "sendLocalNotification");

    Intent notificationIntent = new Intent(this, NotificationActivity.class);
    PendingIntent notificationPendingIntent = PendingIntent.getActivity(this, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Intent startIntent = new Intent(this, FullscreenActivity.class).setAction(Intent.ACTION_VIEW);
    PendingIntent startPendingIntent = PendingIntent.getActivity(this, 0, startIntent, 0);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(NOTIFICATION_TITLE)
            .setContentText(SlideShowData.getInstance().getCount()).setOngoing(true)
            .setContentIntent(startPendingIntent);
    if (SlideShowData.getInstance().hasPreview()) {
        notificationBuilder//from ww  w.j av  a2  s. c  o m
                .extend(new NotificationCompat.WearableExtender().setDisplayIntent(notificationPendingIntent)
                        .setBackground(SlideShowData.getInstance().getPreview()));
    } else {
        notificationBuilder
                .extend(new NotificationCompat.WearableExtender().setDisplayIntent(notificationPendingIntent));
    }

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
}

From source file:org.dmfs.tasks.notification.NotificationUpdaterService.java

private void updatePinnedNotifications(ArrayList<ContentSet> tasksToPin, boolean isReboot, boolean withSound,
        boolean withHeadsUpNotification) {
    ArrayList<Uri> pinnedTaskUris = TaskNotificationHandler.getPinnedTaskUris(this);

    // show notifications
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    for (ContentSet taskContentSet : tasksToPin) {
        boolean isAlreadyShown = pinnedTaskUris.contains(taskContentSet.getUri());
        Integer taskId = TaskFieldAdapters.TASK_ID.get(taskContentSet);
        notificationManager.notify(taskId, makePinNotification(this, mBuilder, taskContentSet,
                !isAlreadyShown || withSound, !isAlreadyShown || withSound, withHeadsUpNotification));
    }//  w w  w .  jav a  2  s  .c o  m

    // remove old notifications
    if (!isReboot) {
        for (Uri uri : pinnedTaskUris) {
            if (uri == null || uri.toString().equals("null")) {
                break;
            }
            long taskId = ContentUris.parseId(uri);
            if (taskId > -1 == !containsTask(tasksToPin, uri)) {

                Integer notificationId = Long.valueOf(ContentUris.parseId(uri)).intValue();
                if (notificationId != null) {
                    notificationManager.cancel(notificationId);
                }
            }
        }
    }
    TaskNotificationHandler.savePinnedTasks(this, tasksToPin);
}

From source file:com.rickendirk.rsgwijzigingen.ZoekService.java

private void sendNotification(Wijzigingen wijzigingen) {
    boolean isFoutMelding = wijzigingen.isFoutmelding();
    boolean isVerbindFout;
    boolean isNieuw; //Tot tegendeel bewezen is
    if (isFoutMelding) {
        isVerbindFout = wijzigingen.isVerbindfout();
        isNieuw = false;//from   w ww .  java  2  s  .co  m
    } else {
        isVerbindFout = false;
        isNieuw = wijzigingen.isNieuw(this);
    }
    if (!isFoutMelding) {
        wijzigingen.saveToSP(this);
    }
    if (!isFoutMelding && !isNieuw) {
        Log.i(TAG, "Geen nieuwe wijzigingen, geen notificatie");
        return;
    }
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_rsg_notific).setContentTitle("Roosterwijzigingen")
            .setColor(getResources().getColor(R.color.lighter_blue))
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS);
    if (isFoutMelding) {
        if (isVerbindFout) {
            Log.i(TAG, "Er was geen internetverbinding bij het zoeken");
            boolean moetHerhalen = PreferenceManager.getDefaultSharedPreferences(this)
                    .getBoolean("pref_auto_herhaal_geenInternet", false);
            if (moetHerhalen) {
                setAlarmIn20Min();
                Log.i(TAG, "Zal ivm geen internet in 20 minuten opnieuw zoeken");
                return;
            } else {
                builder.setContentText("Er was geen internetverbinding. Probeer het handmatig opnieuw");
            }
        } else {
            builder.setContentText("Er was een fout. Probeer het handmatig opnieuw");
        }
    } else {
        boolean zijnWijzigingen = wijzigingen.zijnWijzigingen;
        ArrayList<String> wijzigingenList = wijzigingen.getWijzigingen();
        addPossibleMessage(wijzigingen, wijzigingenList);
        if (zijnWijzigingen) {
            if (wijzigingenList.size() == 1) {
                builder.setContentText(wijzigingenList.get(0));
            } else {
                builder.setContentText("Er zijn " + wijzigingenList.size() + " wijzigingen!");
                NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
                inboxStyle.setBigContentTitle("De roosterwijzigingen zijn:");
                for (int i = 0; i < wijzigingenList.size(); i++) {
                    inboxStyle.addLine(wijzigingenList.get(i));
                }
                builder.setStyle(inboxStyle);
            }
        } else {
            boolean alleenBijWijziging = PreferenceManager.getDefaultSharedPreferences(this)
                    .getBoolean("pref_auto_zoek_alleenBijWijziging", true);
            if (!alleenBijWijziging) {
                //Dus ook bij geen-wijzigingen
                builder.setContentText("Er zijn geen roosterwijzigingen");
            } else
                return;
        }
    }
    Intent resultIntent = new Intent(this, MainActivity.class);
    resultIntent.putExtra("isVanNotificatie", true);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT);
    builder.setContentIntent(pendingIntent);

    NotificationManagerCompat notifManager = NotificationManagerCompat.from(this);
    notifManager.notify(notifID, builder.build());
    vibrate();
    Log.i(TAG, "Nieuwe notificatie gemaakt");
}

From source file:com.stoneapp.ourvlemoodle2.tasks.EventSync.java

public void addNotification(MoodleEvent event) {
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(MainActivity.class);

    Intent resultIntent = new Intent(context, MainActivity.class);
    resultIntent.setAction(BuildConfig.APPLICATION_ID + ".ACTION_OPEN_EVENTS");

    stackBuilder.addNextIntent(resultIntent);

    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_event_available_24dp)
            .setColor(ContextCompat.getColor(context, R.color.colorPrimary)).setContentTitle(event.getName())
            .setContentText(Html.fromHtml(event.getDescription()).toString().trim())
            .setContentIntent(resultPendingIntent).setAutoCancel(true)
            .setDefaults(NotificationCompat.DEFAULT_LIGHTS | NotificationCompat.DEFAULT_SOUND)
            .setCategory(NotificationCompat.CATEGORY_EVENT)
            .setStyle(new NotificationCompat.BigTextStyle()
                    .bigText(Html.fromHtml(event.getDescription()).toString().trim()))
            .addAction(R.drawable.ic_clear_24dp, "Dismiss", null)
            .addAction(R.drawable.ic_add_24dp, "Add Event", null);

    NotificationManagerCompat mNotificationManager = NotificationManagerCompat.from(context);

    mNotificationManager.notify(event.getEventid(), mBuilder.build());
}