@Override public void launch(Activity activity) { RemoteViews remoteViews = new RemoteViews(activity.getPackageName(), R.layout.notification_view); Intent intent = new Intent(activity, SampleGridViewActivity.class); Notification notification = new NotificationCompat.Builder(activity, CHANNEL_ID) .setSmallIcon(R.drawable.icon) .setContentIntent(PendingIntent.getActivity(activity, -1, intent, 0)) .setContent(remoteViews) .setAutoCancel(true) .setChannelId(CHANNEL_ID) .build(); NotificationManager notificationManager = (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "Picasso Notification Channel", NotificationManager.IMPORTANCE_DEFAULT); notificationManager.createNotificationChannel(channel); } notificationManager.notify(NOTIFICATION_ID, notification); // Now load an image for this notification. PicassoProvider.get() // .load(Data.URLS[new Random().nextInt(Data.URLS.length)]) // .resizeDimen(R.dimen.notification_icon_width_height, R.dimen.notification_icon_width_height) // .into(remoteViews, R.id.photo, NOTIFICATION_ID, notification); } };
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()); } }
.setSmallIcon(android.R.drawable.stat_sys_download) .setProgress(100, 0, true) .setChannelId(getBaseContext().getString(R.string.csploitChannelId));
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)); }
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 ShareNotification(Device device) { this.device = device; notificationId = (int) System.currentTimeMillis(); notificationManager = (NotificationManager) device.getContext().getSystemService(Context.NOTIFICATION_SERVICE); builder = new NotificationCompat.Builder(device.getContext(), NotificationHelper.Channels.FILETRANSFER) .setSmallIcon(android.R.drawable.stat_sys_download) .setAutoCancel(true) .setOngoing(true) .setProgress(100, 0, true); }
.setContentTitle(getResources().getString(R.string.notice_activated)) .setDefaults(NotificationCompat.DEFAULT_LIGHTS) .setSmallIcon(R.drawable.ic_security)
.setContentText("") .setContentInfo("") .setSmallIcon(android.R.drawable.ic_popup_sync) .setProgress(100, 0, false) .setChannelId(getBaseContext().getString(R.string.csploitChannelId));
.setSmallIcon(android.R.drawable.ic_popup_sync) .setContentText("") .setProgress(100, 0, false) mBuilder.setSmallIcon(android.R.drawable.stat_sys_download_done) .setContentTitle(getString(R.string.update_available)) .setContentText(getString(R.string.click_here_to_upgrade))
.setSmallIcon(android.R.drawable.ic_popup_sync) .setContentText("") .setContentInfo("")
.setSmallIcon(R.drawable.ic_launcher) .setProgress(100, 0, true);
total )) .setSmallIcon(R.drawable.ic_stat_notify) .setColor(ContextCompat.getColor(context, R.color.material_light_blue_700)) .setContentIntent(PendingIntent.getActivity(
NotificationChannels.getId(NotificationChannels.Channel.GENERAL)) .setCategory(NotificationCompat.CATEGORY_REMINDER) .setSmallIcon(R.drawable.ic_stat_notify) .setColor(ContextCompat.getColor(context, R.color.material_light_blue_700)) .setContentTitle(cardsDueText)
.setSmallIcon(R.drawable.ic_stat_notify) .setContentTitle(title) .setContentText(message)
.setContentText(getString(R.string.installing_bundle)) .setContentInfo("") .setSmallIcon(android.R.drawable.stat_sys_download) .setProgress(100, 0, true) .setChannelId(getBaseContext().getString(R.string.csploitChannelId));
/** * 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()); }