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()); }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.send_notice: Intent intent = new Intent(this, NotificationActivity.class); PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0); NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notification = new NotificationCompat.Builder(this) .setContentTitle("This is content title") .setContentText("This is content text") .setWhen(System.currentTimeMillis()) .setSmallIcon(R.mipmap.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) .setContentIntent(pi) // .setSound(Uri.fromFile(new File("/system/media/audio/ringtones/Luna.ogg"))) // .setVibrate(new long[]{0, 1000, 1000, 1000}) // .setLights(Color.GREEN, 1000, 1000) .setDefaults(NotificationCompat.DEFAULT_ALL) // .setStyle(new NotificationCompat.BigTextStyle().bigText("Learn how to build notifications, send and sync data, and use voice actions. Get the official Android IDE and developer tools to build apps for Android.")) .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(BitmapFactory.decodeResource(getResources(), R.drawable.big_image))) .setPriority(NotificationCompat.PRIORITY_MAX) .build(); manager.notify(1, notification); break; default: break; } }
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) {
mediaStyle.setCancelButtonIntent(stopPendingIntent); builder.setStyle(mediaStyle);
builder.setStyle(inboxStyle); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { builder.setSubText(String.valueOf(transactionCount));
downloadDoneNotification.setStyle(new NotificationCompat.BigTextStyle() .setBigContentTitle(getString(R.string.download_finished)) .bigText(name) 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);
android.R.drawable.stat_sys_download_done) .setContentTitle(ctxt.getString(R.string.title)) .setStyle(style) .addAction(remoteAction);
builder.setStyle(style);
.setStyle(big); NotificationCompat.Builder twoPages= new NotificationCompat.WearableExtender()
@Test public void buildSummaryNotification_withMultiMessageNotification() throws Exception { K9.setNotificationHideSubject(NotificationHideSubject.NEVER); K9.setNotificationQuickDeleteBehaviour(NotificationQuickDelete.ALWAYS); when(notificationData.isSingleMessageNotification()).thenReturn(false); when(notificationData.containsStarredMessages()).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).setContentTitle(NEW_MESSAGE_COUNT + " new messages"); verify(builder).setSubText(ACCOUNT_NAME); verify(builder).setGroup("newMailNotifications-" + ACCOUNT_NUMBER); verify(builder).setGroupSummary(true); verify(builder).setPriority(NotificationCompat.PRIORITY_HIGH); verify(builder).setStyle(notifications.inboxStyle); verify(notifications.inboxStyle).setBigContentTitle(NEW_MESSAGE_COUNT + " new messages"); verify(notifications.inboxStyle).setSummaryText(ACCOUNT_NAME); verify(notifications.inboxStyle).addLine(SUMMARY); verify(notifications.inboxStyle).addLine(SUMMARY_2); verify(builder).addAction(resourceProvider.getIconMarkAsRead(), "Mark Read", null); verify(builder).addAction(resourceProvider.getIconDelete(), "Delete", null); verify(lockScreenNotification).configureLockScreenNotification(builder, notificationData); assertEquals(FAKE_NOTIFICATION, result); }
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); }
private void showSummary() { NotificationCompat.Builder normal=buildNormal(); NotificationCompat.InboxStyle big= new NotificationCompat.InboxStyle(); big.setSummaryText(getString(R.string.summary)) .addLine(getString(R.string.entry)) .addLine(getString(R.string.another_entry)); mgrCompat.notify(NOTIFY_ID, normal.setStyle(big).build()); }