private static NotificationCompat.Builder newNotificationBuilder( Context context, @DrawableRes int smallIcon, String channelId, @Nullable PendingIntent contentIntent, @Nullable String message, @StringRes int titleStringId) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, channelId).setSmallIcon(smallIcon); if (titleStringId != NULL_STRING_ID) { notificationBuilder.setContentTitle(context.getResources().getString(titleStringId)); } if (contentIntent != null) { notificationBuilder.setContentIntent(contentIntent); } if (message != null) { notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message)); } return notificationBuilder; } }
public void notifyFailedDownload(DownloadMission mission) { if (!mDownloadNotificationEnable || mFailedDownloads.indexOfValue(mission) >= 0) return; int id = downloadFailedNotificationID++; mFailedDownloads.put(id, mission); if (downloadFailedNotification == null) { icDownloadFailed = BitmapFactory.decodeResource(this.getResources(), android.R.drawable.stat_sys_warning); downloadFailedNotification = new Builder(this, getString(R.string.notification_channel_id)) .setAutoCancel(true) .setLargeIcon(icDownloadFailed) .setSmallIcon(android.R.drawable.stat_sys_warning) .setContentIntent(mOpenDownloadList); } if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { downloadFailedNotification.setContentTitle(getString(R.string.app_name)); downloadFailedNotification.setStyle(new NotificationCompat.BigTextStyle() .bigText(getString(R.string.download_failed).concat(": ").concat(mission.name))); } else { downloadFailedNotification.setContentTitle(getString(R.string.download_failed)); downloadFailedNotification.setContentText(mission.name); downloadFailedNotification.setStyle(new NotificationCompat.BigTextStyle() .bigText(mission.name)); } notificationManager.notify(id, downloadFailedNotification.build()); }
.setContentTitle(context.getString(R.string.charging_reminder_notification_title)) .setContentText(context.getString(R.string.charging_reminder_notification_body)) .setStyle(new NotificationCompat.BigTextStyle().bigText( context.getString(R.string.charging_reminder_notification_body))) .setDefaults(Notification.DEFAULT_VIBRATE)
notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(alert));
/** * Used by {@link EventProcessor} */ public void showConsentNotification(int notificationId, String text, PendingIntent piAccept, PendingIntent piIgnore) { /** * As we know the id for a specific notification text, * we'll dismiss this notification as it may be outdated. * This is also valid if the notification does not exist. */ mNotificationManager.cancel(notificationId); Notification n = getNotificationBuilder(mInfoChannel) .setContentTitle(mContext.getString(R.string.app_name)) .setContentText(text) .setStyle(new NotificationCompat.BigTextStyle() .bigText(text)) .setContentIntent(piAccept) .addAction(R.drawable.ic_stat_notify, mContext.getString(R.string.accept), piAccept) .addAction(R.drawable.ic_stat_notify, mContext.getString(R.string.ignore), piIgnore) .setSmallIcon(R.drawable.ic_stat_notify) .setAutoCancel(true) .build(); mNotificationManager.notify(notificationId, n); }
public void showStopSyncthingWarningNotification() { final String msg = mContext.getString(R.string.appconfig_receiver_background_enabled); NotificationCompat.Builder nb = getNotificationBuilder(mInfoChannel) .setContentText(msg) .setTicker(msg) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)) .setContentTitle(mContext.getText(mContext.getApplicationInfo().labelRes)) .setSmallIcon(R.drawable.ic_stat_notify) .setAutoCancel(true) .setContentIntent(PendingIntent.getActivity(mContext, 0, new Intent(mContext, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { nb.setCategory(Notification.CATEGORY_ERROR); } mNotificationManager.notify(ID_STOP_BACKGROUND_WARNING, nb.build()); } }
/** * Sets progress message. */ private synchronized void updateProgressNotification() { StringBuilder builder = new StringBuilder(); for (String p : pending) { if (builder.length() > 0) builder.append("\n"); builder.append(p); } if (notificationBuilder != null) { notificationBuilder.setProgress(pending.size() + done.size(), done.size(), false); notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(builder.toString())); notificationBuilder.setContentText(context.getString(R.string.updating_n_host_files, pending.size())); notificationManager.notify(UPDATE_NOTIFICATION_ID, notificationBuilder.build()); } }
public static void remindUserBecauseCharging(Context context) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel mChannel = new NotificationChannel( WATER_REMINDER_NOTIFICATION_CHANNEL_ID, context.getString(R.string.main_notification_channel_name), NotificationManager.IMPORTANCE_HIGH); notificationManager.createNotificationChannel(mChannel); } NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context,WATER_REMINDER_NOTIFICATION_CHANNEL_ID) .setColor(ContextCompat.getColor(context, R.color.colorPrimary)) .setSmallIcon(R.drawable.ic_drink_notification) .setLargeIcon(largeIcon(context)) .setContentTitle(context.getString(R.string.charging_reminder_notification_title)) .setContentText(context.getString(R.string.charging_reminder_notification_body)) .setStyle(new NotificationCompat.BigTextStyle().bigText( context.getString(R.string.charging_reminder_notification_body))) .setDefaults(Notification.DEFAULT_VIBRATE) .setContentIntent(contentIntent(context)) .addAction(drinkWaterAction(context)) .addAction(ignoreReminderAction(context)) .setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { notificationBuilder.setPriority(NotificationCompat.PRIORITY_HIGH); } notificationManager.notify(WATER_REMINDER_NOTIFICATION_ID, notificationBuilder.build()); } private static Action ignoreReminderAction(Context context) {
public static void remindUserBecauseCharging(Context context) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel mChannel = new NotificationChannel( WATER_REMINDER_NOTIFICATION_CHANNEL_ID, context.getString(R.string.main_notification_channel_name), NotificationManager.IMPORTANCE_HIGH); notificationManager.createNotificationChannel(mChannel); } NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context,WATER_REMINDER_NOTIFICATION_CHANNEL_ID) .setColor(ContextCompat.getColor(context, R.color.colorPrimary)) .setSmallIcon(R.drawable.ic_drink_notification) .setLargeIcon(largeIcon(context)) .setContentTitle(context.getString(R.string.charging_reminder_notification_title)) .setContentText(context.getString(R.string.charging_reminder_notification_body)) .setStyle(new NotificationCompat.BigTextStyle().bigText( context.getString(R.string.charging_reminder_notification_body))) .setDefaults(Notification.DEFAULT_VIBRATE) .setContentIntent(contentIntent(context)) .addAction(drinkWaterAction(context)) .addAction(ignoreReminderAction(context)) .setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { notificationBuilder.setPriority(NotificationCompat.PRIORITY_HIGH); } notificationManager.notify(WATER_REMINDER_NOTIFICATION_ID, notificationBuilder.build()); } private static Action ignoreReminderAction(Context context) {
public static void remindUserBecauseCharging(Context context) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel mChannel = new NotificationChannel( WATER_REMINDER_NOTIFICATION_CHANNEL_ID, context.getString(R.string.main_notification_channel_name), NotificationManager.IMPORTANCE_HIGH); notificationManager.createNotificationChannel(mChannel); } NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context,WATER_REMINDER_NOTIFICATION_CHANNEL_ID) .setColor(ContextCompat.getColor(context, R.color.colorPrimary)) .setSmallIcon(R.drawable.ic_drink_notification) .setLargeIcon(largeIcon(context)) .setContentTitle(context.getString(R.string.charging_reminder_notification_title)) .setContentText(context.getString(R.string.charging_reminder_notification_body)) .setStyle(new NotificationCompat.BigTextStyle().bigText( context.getString(R.string.charging_reminder_notification_body))) .setDefaults(Notification.DEFAULT_VIBRATE) .setContentIntent(contentIntent(context)) .addAction(drinkWaterAction(context)) .addAction(ignoreReminderAction(context)) .setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { notificationBuilder.setPriority(NotificationCompat.PRIORITY_HIGH); } notificationManager.notify(WATER_REMINDER_NOTIFICATION_ID, notificationBuilder.build()); } private static Action ignoreReminderAction(Context context) {
public static void remindUserBecauseCharging(Context context) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel mChannel = new NotificationChannel( WATER_REMINDER_NOTIFICATION_CHANNEL_ID, context.getString(R.string.main_notification_channel_name), NotificationManager.IMPORTANCE_HIGH); notificationManager.createNotificationChannel(mChannel); } NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context,WATER_REMINDER_NOTIFICATION_CHANNEL_ID) .setColor(ContextCompat.getColor(context, R.color.colorPrimary)) .setSmallIcon(R.drawable.ic_drink_notification) .setLargeIcon(largeIcon(context)) .setContentTitle(context.getString(R.string.charging_reminder_notification_title)) .setContentText(context.getString(R.string.charging_reminder_notification_body)) .setStyle(new NotificationCompat.BigTextStyle().bigText( context.getString(R.string.charging_reminder_notification_body))) .setDefaults(Notification.DEFAULT_VIBRATE) .setContentIntent(contentIntent(context)) .addAction(drinkWaterAction(context)) .addAction(ignoreReminderAction(context)) .setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { notificationBuilder.setPriority(NotificationCompat.PRIORITY_HIGH); } notificationManager.notify(WATER_REMINDER_NOTIFICATION_ID, notificationBuilder.build()); } private static Action ignoreReminderAction(Context context) {
.setContentTitle(context.getString(R.string.charging_reminder_notification_title)) .setContentText(context.getString(R.string.charging_reminder_notification_body)) .setStyle(new NotificationCompat.BigTextStyle().bigText( context.getString(R.string.charging_reminder_notification_body))) .setDefaults(Notification.DEFAULT_VIBRATE)
public static void remindUserBecauseCharging(Context context) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel mChannel = new NotificationChannel( WATER_REMINDER_NOTIFICATION_CHANNEL_ID, context.getString(R.string.main_notification_channel_name), NotificationManager.IMPORTANCE_HIGH); notificationManager.createNotificationChannel(mChannel); } NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context,WATER_REMINDER_NOTIFICATION_CHANNEL_ID) .setColor(ContextCompat.getColor(context, R.color.colorPrimary)) .setSmallIcon(R.drawable.ic_drink_notification) .setLargeIcon(largeIcon(context)) .setContentTitle(context.getString(R.string.charging_reminder_notification_title)) .setContentText(context.getString(R.string.charging_reminder_notification_body)) .setStyle(new NotificationCompat.BigTextStyle().bigText( context.getString(R.string.charging_reminder_notification_body))) .setDefaults(Notification.DEFAULT_VIBRATE) .setContentIntent(contentIntent(context)) .addAction(drinkWaterAction(context)) .addAction(ignoreReminderAction(context)) .setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { notificationBuilder.setPriority(NotificationCompat.PRIORITY_HIGH); } notificationManager.notify(WATER_REMINDER_NOTIFICATION_ID, notificationBuilder.build()); } private static Action ignoreReminderAction(Context context) {
public static void remindUserBecauseCharging(Context context) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel mChannel = new NotificationChannel( WATER_REMINDER_NOTIFICATION_CHANNEL_ID, context.getString(R.string.main_notification_channel_name), NotificationManager.IMPORTANCE_HIGH); notificationManager.createNotificationChannel(mChannel); } NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context,WATER_REMINDER_NOTIFICATION_CHANNEL_ID) .setColor(ContextCompat.getColor(context, R.color.colorPrimary)) .setSmallIcon(R.drawable.ic_drink_notification) .setLargeIcon(largeIcon(context)) .setContentTitle(context.getString(R.string.charging_reminder_notification_title)) .setContentText(context.getString(R.string.charging_reminder_notification_body)) .setStyle(new NotificationCompat.BigTextStyle().bigText( context.getString(R.string.charging_reminder_notification_body))) .setDefaults(Notification.DEFAULT_VIBRATE) .setContentIntent(contentIntent(context)) .addAction(drinkWaterAction(context)) .addAction(ignoreReminderAction(context)) .setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { notificationBuilder.setPriority(NotificationCompat.PRIORITY_HIGH); } notificationManager.notify(WATER_REMINDER_NOTIFICATION_ID, notificationBuilder.build()); } private static Action ignoreReminderAction(Context context) {
downloadDoneNotification.setStyle(new NotificationCompat.BigTextStyle() .setBigContentTitle(getString(R.string.download_finished)) .bigText(name) ); } else { downloadDoneList.append(name); downloadDoneNotification.setStyle(new NotificationCompat.BigTextStyle().bigText(downloadDoneList)); downloadDoneNotification.setContentTitle(getString(R.string.download_finished_more, String.valueOf(downloadDoneCount + 1))); downloadDoneNotification.setContentText(downloadDoneList);
public void showAuthenticationErrorNotification(Account account, boolean incoming) { int notificationId = NotificationIds.getAuthenticationErrorNotificationId(account, incoming); PendingIntent editServerSettingsPendingIntent = createContentIntent(account, incoming); String title = resourceProvider.authenticationErrorTitle(); String text = resourceProvider.authenticationErrorBody(account.getDescription()); NotificationCompat.Builder builder = notificationHelper .createNotificationBuilder(account, NotificationChannelManager.ChannelType.MISCELLANEOUS) .setSmallIcon(resourceProvider.getIconWarning()) .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setTicker(title) .setContentTitle(title) .setContentText(text) .setContentIntent(editServerSettingsPendingIntent) .setStyle(new BigTextStyle().bigText(text)) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setCategory(NotificationCompat.CATEGORY_ERROR); notificationHelper.configureNotification(builder, null, null, NOTIFICATION_LED_FAILURE_COLOR, NOTIFICATION_LED_BLINK_FAST, true); getNotificationManager().notify(notificationId, builder.build()); }
@Test public void buildSummaryNotification_withSingleMessageNotification() throws Exception { K9.setNotificationHideSubject(NotificationHideSubject.NEVER); K9.setNotificationQuickDeleteBehaviour(NotificationQuickDelete.ALWAYS); when(notificationData.isSingleMessageNotification()).thenReturn(true); Notification result = notifications.buildSummaryNotification(account, notificationData, false); verify(builder).setSmallIcon(resourceProvider.getIconNewMail()); verify(builder).setColor(ACCOUNT_COLOR); verify(builder).setAutoCancel(true); verify(builder).setTicker(SUMMARY); verify(builder).setContentText(SUBJECT); verify(builder).setContentTitle(SENDER); verify(builder).setStyle(notifications.bigTextStyle); verify(notifications.bigTextStyle).bigText(PREVIEW); verify(builder).addAction(resourceProvider.getIconReply(), "Reply", null); verify(builder).addAction(resourceProvider.getIconMarkAsRead(), "Mark Read", null); verify(builder).addAction(resourceProvider.getIconDelete(), "Delete", null); verify(lockScreenNotification).configureLockScreenNotification(builder, notificationData); assertEquals(FAKE_NOTIFICATION, result); }
protected NotificationCompat.Builder createBigTextStyleNotification(Account account, NotificationHolder holder, int notificationId) { String accountName = notificationHelper.getAccountName(account); NotificationContent content = holder.content; String groupKey = NotificationGroupKeys.getGroupKey(account); NotificationCompat.Builder builder = createAndInitializeNotificationBuilder(account) .setTicker(content.summary) .setGroup(groupKey) .setContentTitle(content.sender) .setContentText(content.subject) .setSubText(accountName); NotificationCompat.BigTextStyle style = createBigTextStyle(builder); style.bigText(content.preview); builder.setStyle(style); PendingIntent contentIntent = actionCreator.createViewMessagePendingIntent( content.messageReference, notificationId); builder.setContentIntent(contentIntent); return builder; }
protected void postErrorResult(String title, String text) { disposeAll(); stopForeground(true); stopSelf(); if (title == null) { return; } text = text == null ? "" : text; notificationBuilder = new NotificationCompat.Builder(this, getString(R.string.notification_channel_id)) .setSmallIcon(R.drawable.ic_newpipe_triangle_white) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setContentTitle(title) .setStyle(new NotificationCompat.BigTextStyle().bigText(text)) .setContentText(text); notificationManager.notify(getNotificationId(), notificationBuilder.build()); }
@Test public void testCreateBigTextStyleNotification() throws Exception { Account account = createFakeAccount(); int notificationId = 23; NotificationHolder holder = createNotificationHolder(notificationId); Builder builder = notifications.createBigTextStyleNotification(account, holder, notificationId); verify(builder).setTicker(NOTIFICATION_SUMMARY); verify(builder).setGroup("newMailNotifications-" + ACCOUNT_NUMBER); verify(builder).setContentTitle(SENDER); verify(builder).setContentText(SUBJECT); verify(builder).setSubText(ACCOUNT_NAME); BigTextStyle bigTextStyle = notifications.bigTextStyle; verify(bigTextStyle).bigText(NOTIFICATION_PREVIEW); verify(builder).setStyle(bigTextStyle); }