Source:
public void updateReport(List<DownloadStatus> reportQueue, boolean showAutoDownloadReport) { boolean createReport = false; int successfulDownloads = 0; int failedDownloads = 0; for (DownloadStatus status : reportQueue) { if (status.isSuccessful()) { successfulDownloads++; } else if (!status.isCancelled()) { failedDownloads++; } if (failedDownloads > 0 || showAutoDownloadReport && !status.isInitiatedByUser() && status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) { createReport = true; } } if (createReport) { Log.d(TAG, "Creating report"); NotificationCompat.Builder builder = new NotificationCompat.Builder(context, NotificationUtils.CHANNEL_ID_ERROR) .setTicker(context.getString(R.string.download_report_title)) .setContentTitle(context.getString(R.string.download_report_content_title)) .setContentText( String.format( context.getString(R.string.download_report_content), successfulDownloads, failedDownloads) ) .setSmallIcon(R.drawable.stat_notify_sync_error) .setContentIntent( ClientConfig.downloadServiceCallbacks.getReportNotificationContentIntent(context) ) .setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); } NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(REPORT_ID, builder.build()); } else { Log.d(TAG, "No report is created"); } }

Target:
public void updateReport(List<DownloadStatus> reportQueue, boolean showAutoDownloadReport) { boolean createReport = false; int successfulDownloads = 0; int failedDownloads = 0; for (DownloadStatus status : reportQueue) { if (status.isSuccessful()) { successfulDownloads++; createReport |= showAutoDownloadReport && !status.isInitiatedByUser() && status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA; } else if (!status.isCancelled()) { failedDownloads++; createReport = true; } } if (createReport) { Log.d(TAG, "Creating report"); String channelId; int titleId; int iconId; int id; String content; PendingIntent intent; if (failedDownloads == 0) { channelId = NotificationUtils.CHANNEL_ID_AUTO_DOWNLOAD; titleId = R.string.auto_download_report_title; iconId = R.drawable.auto_download_complete; intent = ClientConfig.downloadServiceCallbacks.getAutoDownloadReportNotificationContentIntent(context); id = AUTO_REPORT_ID; content = createAutoDownloadNotificationContent(reportQueue); } else { channelId = NotificationUtils.CHANNEL_ID_ERROR; titleId = R.string.download_report_title; iconId = R.drawable.stat_notify_sync_error; intent = ClientConfig.downloadServiceCallbacks.getReportNotificationContentIntent(context); id = REPORT_ID; content = String.format(context.getString(R.string.download_report_content), successfulDownloads, failedDownloads); } NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId); builder.setTicker(context.getString(titleId)) .setContentTitle(context.getString(titleId)) .setContentText(content) .setStyle(new NotificationCompat.BigTextStyle().bigText(content)) .setSmallIcon(iconId) .setContentIntent(intent) .setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); } NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(id, builder.build()); } else { Log.d(TAG, "No report is created"); } }