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()); } }
.setContentText(getString(R.string.connecting)) .setSmallIcon(android.R.drawable.stat_sys_download) .setProgress(100, 0, true) previous_percentage=-1; mBuilder.setContentText(file.getName()) .setChannelId(getBaseContext().getString(R.string.csploitChannelId)); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
.setContentText("") .setContentInfo("") .setSmallIcon(android.R.drawable.ic_popup_sync)
public void setProgress(int progress, String progressMessage) { builder.setProgress( 100, progress, false); builder.setContentText(progressMessage); }
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++; } }
public Notification getNotification(String message) { return new NotificationCompat.Builder(getApplicationContext(), MainActivity.id1) .setSmallIcon(R.mipmap.ic_launcher) .setOngoing(true) //persistent notification! .setChannelId(MainActivity.id1) .setContentTitle("Service") //Title message top row. .setContentText(message) //message when looking at the notification, second row .build(); //finally build and return a Notification. } }
@Override public NotificationBuilder setContentText(final CharSequence text) { super.setContentText(text); return this; }
private void updateText() { String text; text = res.getQuantityString(R.plurals.outgoing_files_text, numFiles, sentFiles, numFiles); builder.setContentText(text); }
@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++; }
@Override protected void buildNotification(Context context, NotificationCompat.Builder notification, int notificationId) { super.buildNotification(context, notification, notificationId); notification.setContentText(context.getString(R.string.certificate_error, getServerName())); Intent notificationIntent = new Intent(context, MainActivity.class); notificationIntent.putExtra(MainActivity.ARG_SERVER_UUID, mServerUUID.toString()); notification.setContentIntent(PendingIntent.getActivity(context, notificationId, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT)); }
mBuilder.setContentTitle(getString(R.string.checking)) .setSmallIcon(android.R.drawable.ic_popup_sync) .setContentText("") .setProgress(100, 0, false) .setChannelId(getBaseContext().getString(R.string.csploitChannelId)); mBuilder.setSmallIcon(android.R.drawable.stat_sys_download_done) .setContentTitle(getString(R.string.update_available)) .setContentText(getString(R.string.click_here_to_upgrade)) .setProgress(0, 0, false) // remove progress bar .setAutoCancel(true);
.setContentText("") .setContentInfo("") .setProgress(100, 0, true)
.setCategory(NotificationCompat.CATEGORY_REMINDER) .setContentTitle(context.getString(R.string.reminder_title)) .setContentText(context.getResources().getQuantityString( R.plurals.reminder_text, total,
.setSmallIcon(R.drawable.ic_stat_notify) .setContentTitle(title) .setContentText(message) .setColor(ContextCompat.getColor(this, R.color.material_light_blue_500)) .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
.setContentText(getString(R.string.installing_bundle)) .setContentInfo("") .setSmallIcon(android.R.drawable.stat_sys_download) mBuilder.setContentText(getString(R.string.installing_msf_gems)) .setChannelId(getBaseContext().getString(R.string.csploitChannelId)); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
/** * 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()); }