private void updateNotificationForStatus(Context context, MsfRpcdService.Status status) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, context.getString(R.string.csploitChannelId)) .setSmallIcon(R.drawable.exploit_msf) .setContentTitle(context.getString(R.string.msf_status)) .setProgress(0, 0, status.inProgress()) .setContentText(context.getString(status.getText())) .setColor(ContextCompat.getColor(context, status.getColor())) .setChannelId(context.getString(R.string.csploitChannelId)); NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(MSF_NOTIFICATION, mBuilder.build()); } }
long downloaded,total; mBuilder.setContentTitle(getString(R.string.downloading_update)) .setContentText(getString(R.string.connecting)) .setSmallIcon(android.R.drawable.stat_sys_download)
.setSmallIcon(R.drawable.ic_stat_notify) .setColor(ContextCompat.getColor(context, R.color.material_light_blue_700)) .setContentTitle(cardsDueText) .setTicker(cardsDueText);
public void setFinished(String message) { builder = new NotificationCompat.Builder(device.getContext(), NotificationHelper.Channels.DEFAULT); builder.setContentTitle(message) .setTicker(message) .setSmallIcon(android.R.drawable.stat_sys_download_done) .setAutoCancel(true) .setOngoing(false); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(device.getContext()); if (prefs.getBoolean("share_notification_preference", true)) { builder.setDefaults(Notification.DEFAULT_ALL); } }
protected void buildNotification(Context context, NotificationCompat.Builder notification, int notificationId) { notification.setSmallIcon(R.drawable.ic_warning); notification.setPriority(NotificationCompat.PRIORITY_HIGH); notification.setContentTitle(context.getString(R.string.notification_action_required)); }
@Override protected void buildNotification(Context context, NotificationCompat.Builder notification, int notificationId) { super.buildNotification(context, notification, notificationId); notification.setPriority(NotificationCompat.PRIORITY_DEFAULT); notification.setContentTitle(context.getString(R.string.connection_error_command_title)); notification.setContentText(context.getString(R.string.connection_error_command_notification_desc)); notification.setContentIntent(PendingIntent.getActivity(context, notificationId, MainActivity.getLaunchIntent(context, null, null), PendingIntent.FLAG_CANCEL_CURRENT)); }
public void makenoti(String message) { Notification noti = new NotificationCompat.Builder(getApplicationContext(), MainActivity.id) .setSmallIcon(R.drawable.ic_launcher) .setWhen(System.currentTimeMillis()) //When the event occurred, now, since noti are stored by time. .setContentTitle("Service") //Title message top row. .setContentText(message) //message when looking at the notification, second row .setAutoCancel(true) //allow auto cancel when pressed. .build(); //finally build and return a Notification. //Show the notification nm.notify(NotID, noti); NotID++; }
new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); builder.setWhen(0) .setContentTitle(getResources().getString(R.string.notice_activated)) .setDefaults(NotificationCompat.DEFAULT_LIGHTS) .setSmallIcon(R.drawable.ic_security)
private void updateUserInterface() { long time = System.currentTimeMillis(); if (time - lastUpdate >= 1000) { lastUpdate = time; if (notification != null) { notification.setContentTitle(getResources().getString(R.string.notice_queries) + " " + String.valueOf(provider.getDnsQueryTimes())); NotificationManager manager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(NOTIFICATION_ACTIVATED, notification.build()); } } }
return; mBuilder.setContentTitle(getString(R.string.extracting)) .setContentText("") .setContentInfo("")
mBuilder.setContentTitle(getString(R.string.checking)) .setSmallIcon(android.R.drawable.ic_popup_sync) .setContentText("") .setContentTitle(getString(R.string.update_available)) .setContentText(getString(R.string.click_here_to_upgrade)) .setProgress(0, 0, false) // remove progress bar
throw new RuntimeException("no archive to test"); mBuilder.setContentTitle(getString(R.string.checking)) .setSmallIcon(android.R.drawable.ic_popup_sync) .setContentText("")
mBuilder.setContentTitle(getString(R.string.multiple_attack)) .setSmallIcon(R.drawable.ic_launcher) .setProgress(100, 0, true);
NotificationChannels.getId(NotificationChannels.Channel.DECK_REMINDERS)) .setCategory(NotificationCompat.CATEGORY_REMINDER) .setContentTitle(context.getString(R.string.reminder_title)) .setContentText(context.getResources().getQuantityString( R.plurals.reminder_text,
NotificationChannels.getId(channel)) .setSmallIcon(R.drawable.ic_stat_notify) .setContentTitle(title) .setContentText(message) .setColor(ContextCompat.getColor(this, R.color.material_light_blue_500))
String msfPath = System.getMsfPath(); mBuilder.setContentTitle(getString(R.string.installing_gems)) .setContentText(getString(R.string.installing_bundle)) .setContentInfo("")
/** * Informs the {@link UploadService} that the task has made some progress. You should call this * method from your task whenever you have successfully transferred some bytes to the server. * * @param uploadInfo upload information and statistics */ private void updateNotificationProgress(UploadInfo uploadInfo) { if (params.notificationConfig == null || params.notificationConfig.getProgress().message == null) return; UploadNotificationStatusConfig statusConfig = params.notificationConfig.getProgress(); NotificationCompat.Builder notification = new NotificationCompat.Builder(service, params.notificationConfig.getNotificationChannelId()) .setWhen(notificationCreationTimeMillis) .setContentTitle(Placeholders.replace(statusConfig.title, uploadInfo)) .setContentText(Placeholders.replace(statusConfig.message, uploadInfo)) .setContentIntent(statusConfig.getClickIntent(service)) .setSmallIcon(statusConfig.iconResourceID) .setLargeIcon(statusConfig.largeIcon) .setColor(statusConfig.iconColorResourceID) .setGroup(UploadService.NAMESPACE) .setProgress((int) uploadInfo.getTotalBytes(), (int) uploadInfo.getUploadedBytes(), false) .setOngoing(true); statusConfig.addActionsToNotificationBuilder(notification); Notification builtNotification = notification.build(); if (service.holdForegroundNotification(params.id, builtNotification)) { notificationManager.cancel(notificationId); } else { notificationManager.notify(notificationId, builtNotification); } }
/** * If the upload task is initialized with a notification configuration, this handles its * creation. * * @param uploadInfo upload information and statistics */ private void createNotification(UploadInfo uploadInfo) { if (params.notificationConfig == null || params.notificationConfig.getProgress().message == null) return; UploadNotificationStatusConfig statusConfig = params.notificationConfig.getProgress(); notificationCreationTimeMillis = System.currentTimeMillis(); NotificationCompat.Builder notification = new NotificationCompat.Builder(service, params.notificationConfig.getNotificationChannelId()) .setWhen(notificationCreationTimeMillis) .setContentTitle(Placeholders.replace(statusConfig.title, uploadInfo)) .setContentText(Placeholders.replace(statusConfig.message, uploadInfo)) .setContentIntent(statusConfig.getClickIntent(service)) .setSmallIcon(statusConfig.iconResourceID) .setLargeIcon(statusConfig.largeIcon) .setColor(statusConfig.iconColorResourceID) .setGroup(UploadService.NAMESPACE) .setProgress(100, 0, true) .setOngoing(true); statusConfig.addActionsToNotificationBuilder(notification); Notification builtNotification = notification.build(); if (service.holdForegroundNotification(params.id, builtNotification)) { notificationManager.cancel(notificationId); } else { notificationManager.notify(notificationId, builtNotification); } }
private void updateNotification(UploadInfo uploadInfo, UploadNotificationStatusConfig statusConfig) { if (params.notificationConfig == null) return; notificationManager.cancel(notificationId); if (statusConfig.message == null) return; if (!statusConfig.autoClear) { NotificationCompat.Builder notification = new NotificationCompat.Builder(service, params.notificationConfig.getNotificationChannelId()) .setContentTitle(Placeholders.replace(statusConfig.title, uploadInfo)) .setContentText(Placeholders.replace(statusConfig.message, uploadInfo)) .setContentIntent(statusConfig.getClickIntent(service)) .setAutoCancel(statusConfig.clearOnAction) .setSmallIcon(statusConfig.iconResourceID) .setLargeIcon(statusConfig.largeIcon) .setColor(statusConfig.iconColorResourceID) .setGroup(UploadService.NAMESPACE) .setProgress(0, 0, false) .setOngoing(false); statusConfig.addActionsToNotificationBuilder(notification); setRingtone(notification); // this is needed because the main notification used to show progress is ongoing // and a new one has to be created to allow the user to dismiss it uploadInfo.setNotificationID(notificationId + 1); notificationManager.notify(notificationId + 1, notification.build()); } }
/** * Show a notification while this service is running. */ @SuppressWarnings("deprecation") private void showNotification() { Intent toLaunch = new Intent(getApplicationContext(), MonitorActivity.class); toLaunch.setAction(Intent.ACTION_MAIN); toLaunch.addCategory(Intent.CATEGORY_LAUNCHER); toLaunch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent resultPendingIntent = PendingIntent.getActivity( this, 0, toLaunch, PendingIntent.FLAG_UPDATE_CURRENT ); // In this sample, we'll use the same text for the ticker and the expanded notification CharSequence text = getText(R.string.secure_service_started); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, channelId) .setSmallIcon(R.drawable.ic_stat_haven) .setContentTitle(getString(R.string.app_name)) .setContentText(text); mBuilder.setPriority(NotificationCompat.PRIORITY_MIN); mBuilder.setContentIntent(resultPendingIntent); mBuilder.setWhen(System.currentTimeMillis()); mBuilder.setVisibility(NotificationCompat.VISIBILITY_SECRET); startForeground(1, mBuilder.build()); }