Showing notifications

Simple snippet for showing a notification. Tweak where needed.

Note: we suggest using the Navigation Component to generate the deeplinks for the PendingIntent instead.

        Intent intent = new Intent(context, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(
                context,
                0,
                intent,
                PendingIntent.FLAG_UPDATE_CURRENT
        );

        final Notification notification = new Builder(context)
                .setContentTitle(getString(R.string.app_name))
                .setContentText(getString(R.string.notification_text))
                .setOnlyAlertOnce(true)
                .setColor(ContextCompat.getColor(context, R.color.colorAccent))
                .addAction(R.id.ic_notification_action, getString(R.string.notification_action)
                        , pendingIntent)
                .setOngoing(false)
                .setPriority(NotificationCompat.PRIORITY_LOW)
                .build();

        NotificationManager manager =
                (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        manager.notify(NOTIFICATION_ID, notification);