new NotificationCompat.Builder(context, NotificationChannels.getId(NotificationChannels.Channel.GENERAL)) .setCategory(NotificationCompat.CATEGORY_REMINDER) .setSmallIcon(R.drawable.ic_stat_notify) .setColor(ContextCompat.getColor(context, R.color.material_light_blue_700))
new NotificationCompat.Builder(context, NotificationChannels.getId(NotificationChannels.Channel.DECK_REMINDERS)) .setCategory(NotificationCompat.CATEGORY_REMINDER) .setContentTitle(context.getString(R.string.reminder_title)) .setContentText(context.getResources().getQuantityString(
builder.setCategory(Notification.CATEGORY_STATUS);
.setDefaults(defaultFlags) .setPriority(NotificationCompat.PRIORITY_HIGH) .setCategory(NotificationCompat.CATEGORY_EVENT) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
.setCategory(Notification.CATEGORY_EMAIL)
.setSubText(Integer.toString(1)) .addAction(replyAction) .setCategory(Notification.CATEGORY_SOCIAL) .setPriority(bigPictureStyleSocialAppData.getPriority()) .setVisibility(bigPictureStyleSocialAppData.getChannelLockscreenVisibility())
.setSubText(Integer.toString(1)) .addAction(replyAction) .setCategory(Notification.CATEGORY_SOCIAL) .setPriority(Notification.PRIORITY_HIGH) .setVisibility(Notification.VISIBILITY_PRIVATE);
.setContentIntent(notifyPendingIntent) .setColor(getResources().getColor(R.color.colorPrimary)) .setCategory(Notification.CATEGORY_REMINDER) .setPriority(Notification.PRIORITY_HIGH) .setVisibility(Notification.VISIBILITY_PUBLIC)
@TargetApi(Build.VERSION_CODES.N) private static void createSummaryGroupNotification( Context ctx, Account account, Set<String> notifications, boolean feedback) { int notificationId = FowlerNollVo.fnv1_32(account.getAccountHash().getBytes()).intValue(); NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx, account.getAccountHash()) .setContentTitle(getNotificationSubText(account)) .setSubText(getNotificationSubText(account)) .setSmallIcon(R.drawable.ic_stat_notify) .setAutoCancel(true) .setCategory(NotificationCompat.CATEGORY_SOCIAL) .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setDefaults(feedback ? NotificationCompat.DEFAULT_ALL : 0) .setColor(ContextCompat.getColor(ctx, R.color.primaryDark)) .setContentIntent( getViewAccountChangesPendingIntent(ctx, account, notificationId)) .setDeleteIntent( getDeleteAccountNotificationPendingIntent(ctx, account, notificationId)) .setOnlyAlertOnce(true) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC); NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle() .setSummaryText(getNotificationSubText(account)); builder.setStyle(style) .setNumber(notifications.size()) .setGroupSummary(true) .setGroup(NOTIFICATION_KEY_GROUP + account.getAccountHash()); publishNotification(ctx, builder.build(), notificationId); }
private void makeForegroundNotify() { /* For starting main activity */ Intent startupIntent = new Intent(getApplicationContext(), MainActivity.class); startupIntent.setAction(Intent.ACTION_MAIN); startupIntent.addCategory(Intent.CATEGORY_LAUNCHER); startupIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent startupPendingIntent = PendingIntent.getActivity( getApplicationContext(), 0, startupIntent, PendingIntent.FLAG_UPDATE_CURRENT); foregroundNotify = new NotificationCompat.Builder(getApplicationContext(), FOREGROUND_NOTIFY_CHAN_ID) .setSmallIcon(R.drawable.ic_app_notification) .setContentIntent(startupPendingIntent) .setContentTitle(getString(R.string.app_running_in_the_background)) .setTicker(getString(R.string.app_running_in_the_background)) .setContentText((isNetworkOnline ? getString(R.string.network_online) : getString(R.string.network_offline))) .setWhen(System.currentTimeMillis()); foregroundNotify.addAction(makeFuncButtonAction()); foregroundNotify.addAction(makeShutdownAction()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) foregroundNotify.setCategory(Notification.CATEGORY_SERVICE); /* Disallow killing the service process by system */ startForeground(SERVICE_STARTED_NOTIFICATION_ID, foregroundNotify.build()); }
/** * Show notification * * @param mId Notification Id */ @SuppressWarnings("SameParameterValue") private Notification showNotification(int mId) { if (Logger.DEBUG) { Log.d(TAG, "[showNotification " + mId + "]"); } final String channelId = String.valueOf(mId); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { createNotificationChannel(channelId); } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, channelId) .setSmallIcon(R.drawable.ic_stat_notify_24dp) .setContentTitle(getString(R.string.app_name)) .setPriority(NotificationCompat.PRIORITY_HIGH) .setCategory(NotificationCompat.CATEGORY_SERVICE) .setContentText(String.format(getString(R.string.is_running), getString(R.string.app_name))); Intent resultIntent = new Intent(this, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); Notification mNotification = mBuilder.build(); mNotificationManager.notify(mId, mNotification); return mNotification; }
private synchronized void makeTorrentsMoveNotify() { if (torrentsMoveTotal == null || torrentsMoveSuccess == null || torrentsMoveFailed == null) { return; } NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(), DEFAULT_CHAN_ID); String resultTemplate = getString(R.string.torrents_moved_content); int successfully = torrentsMoveSuccess.size(); int failed = torrentsMoveFailed.size(); builder.setContentTitle(getString(R.string.torrents_moved_title)) .setTicker(getString(R.string.torrents_moved_title)) .setContentText(String.format(resultTemplate, successfully, failed)); builder.setSmallIcon(R.drawable.ic_folder_move_white_24dp) .setAutoCancel(true) .setWhen(System.currentTimeMillis()) .setStyle(makeTorrentsMoveInboxStyle(torrentsMoveSuccess, torrentsMoveFailed)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setCategory(Notification.CATEGORY_STATUS); } notifyManager.notify(TORRENTS_MOVED_NOTIFICATION_ID, builder.build()); torrentsMoveTotal = null; torrentsMoveSuccess = null; torrentsMoveFailed = null; }
public static Notification getFTPRunning(Context context, String title, String text, PendingIntent intent) { NotificationCompat.Builder builder = new NotificationCompat.Builder(context, NotificationChannelHelper.getChannelLow(context)) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)) .setSmallIcon(R.drawable.ic_notification_ftp) .setColor(ContextCompat.getColor(context, R.color.colorPrimary)) .setDefaults(NotificationCompat.DEFAULT_ALL) .setCategory(NotificationCompat.CATEGORY_SERVICE) .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setVisibility(NotificationCompat.VISIBILITY_PRIVATE) .setAutoCancel(false) .setOngoing(true) .setContentTitle(title) .setContentText(text) .setContentIntent(intent); return builder.build(); } }
private static NotificationCompat.Builder createNotificationBuilder( Context ctx, Account account, NotificationEntity entity, boolean feedback) { return new NotificationCompat.Builder(ctx, account.getAccountHash()) .setContentTitle(entity.mNotification.subject) .setContentText(getContentTitle(ctx, entity, true)) .setSubText(getNotificationSubText(account)) .setSmallIcon(R.drawable.ic_stat_notify) .setAutoCancel(true) .setCategory(NotificationCompat.CATEGORY_SOCIAL) .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setDefaults(feedback ? NotificationCompat.DEFAULT_ALL : 0) .setWhen(entity.mWhen) .setColor(ContextCompat.getColor(ctx, R.color.primaryDark)) .setContentIntent(getViewChangePendingIntent(ctx, entity)) .setDeleteIntent(getDeleteGroupNotificationPendingIntent(ctx, entity.mGroupId)) .setOnlyAlertOnce(true) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC); }
private void makeTorrentInfoNotify(String name, String message) { if (name == null || message == null) return; NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(), DEFAULT_CHAN_ID) .setSmallIcon(R.drawable.ic_info_white_24dp) .setColor(ContextCompat.getColor(getApplicationContext(), R.color.primary)) .setContentTitle(name) .setTicker(message) .setContentText(message) .setAutoCancel(true) .setWhen(System.currentTimeMillis()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) builder.setCategory(Notification.CATEGORY_STATUS); notifyManager.notify(name.hashCode(), builder.build()); }
private void makeTorrentErrorNotify(String name, String message) { if (name == null || message == null) return; NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(), DEFAULT_CHAN_ID) .setSmallIcon(R.drawable.ic_error_white_24dp) .setColor(ContextCompat.getColor(getApplicationContext(), R.color.primary)) .setContentTitle(name) .setTicker(getString(R.string.torrent_error_notify_title)) .setContentText(String.format(getString(R.string.error_template), message)) .setAutoCancel(true) .setWhen(System.currentTimeMillis()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) builder.setCategory(Notification.CATEGORY_ERROR); notifyManager.notify(name.hashCode(), builder.build()); }
private void makeNatErrorNotify(String message) { if (message == null) return; NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(), DEFAULT_CHAN_ID) .setSmallIcon(R.drawable.ic_error_white_24dp) .setColor(ContextCompat.getColor(getApplicationContext(), R.color.primary)) .setContentTitle(getString(R.string.nat_error_title)) .setTicker(getString(R.string.nat_error_title)) .setContentText(String.format(getString(R.string.error_template), message)) .setAutoCancel(true) .setWhen(System.currentTimeMillis()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) builder.setCategory(Notification.CATEGORY_ERROR); notifyManager.notify(NAT_ERROR_NOTIFICATION_ID, builder.build()); }
private void makeTorrentAddedNotify(String name) { if (name == null) return; String title = getString(R.string.torrent_added_notify); NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(), DEFAULT_CHAN_ID) .setSmallIcon(R.drawable.ic_done_white_24dp) .setColor(ContextCompat.getColor(getApplicationContext(), R.color.primary)) .setContentTitle(title) .setTicker(title) .setContentText(name) .setAutoCancel(true) .setWhen(System.currentTimeMillis()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) builder.setCategory(Notification.CATEGORY_STATUS); notifyManager.notify(name.hashCode(), builder.build()); }
private void makeSessionErrorNotify(String message) { if (message == null) return; NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(), DEFAULT_CHAN_ID) .setSmallIcon(R.drawable.ic_error_white_24dp) .setColor(ContextCompat.getColor(getApplicationContext(), R.color.primary)) .setContentTitle(getString(R.string.session_error_title)) .setTicker(getString(R.string.session_error_title)) .setContentText(String.format(getString(R.string.error_template), message)) .setAutoCancel(true) .setWhen(System.currentTimeMillis()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) builder.setCategory(Notification.CATEGORY_ERROR); notifyManager.notify(SESSION_ERROR_NOTIFICATION_ID, builder.build()); }
@Override public NotificationBuilder setCategory(final String category) { super.setCategory(category); return this; }