@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()); } }
.setProgress(100, 0, true) .setChannelId(getBaseContext().getString(R.string.csploitChannelId)); mNotificationManager.notify(NOTIFICATION_ID,mBuilder.build()); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); .setContentInfo(percentage + "%") .setChannelId(getBaseContext().getString(R.string.csploitChannelId)); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); previous_percentage = percentage;
private void updateForegroundNotifyActions() { if (foregroundNotify == null) return; foregroundNotify.mActions.clear(); foregroundNotify.addAction(makeFuncButtonAction()); foregroundNotify.addAction(makeShutdownAction()); startForeground(SERVICE_STARTED_NOTIFICATION_ID, foregroundNotify.build()); }
settingsIntent, PendingIntent.FLAG_UPDATE_CURRENT)); Notification notification = builder.build();
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()); } } }
.setProgress(100, 0, false) .setChannelId(getBaseContext().getString(R.string.csploitChannelId)); mNotificationManager.notify(NOTIFICATION_ID,mBuilder.build()); .setContentInfo(percentage + "%") .setChannelId(getBaseContext().getString(R.string.csploitChannelId)); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); old_percentage = percentage; .setProgress(100, 100, true) .setChannelId(getBaseContext().getString(R.string.csploitChannelId)); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } finally { if(is != null)
.setProgress(100, 0, false) .setChannelId(getBaseContext().getString(R.string.csploitChannelId)); mNotificationManager.notify(NOTIFICATION_ID,mBuilder.build()); .setContentInfo(percentage + "%") .setChannelId(getBaseContext().getString(R.string.csploitChannelId)); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); previous_percentage = percentage;
.setProgress(100, 0, true) .setChannelId(getBaseContext().getString(R.string.csploitChannelId)); mNotificationManager.notify(NOTIFICATION_ID,mBuilder.build()); .setContentInfo(percentage + "%") .setChannelId(getBaseContext().getString(R.string.csploitChannelId)); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); old_percentage = percentage;
)) .setAutoCancel(true) .build(); notificationManager.notify((int) deckId, notification);
builder.setContentIntent(resultPendingIntent); manager.notify(WIDGET_NOTIFY_ID, builder.build()); } else {
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(SIMPLE_NOTIFICATION_ID, builder.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); } }
@Override public void run() { try { if((tasks&TRACE)!=0) trace(); if((tasks&SCAN)!=0) scan(); if((tasks&INSPECT)!=0) inspect(); if((tasks&EXPLOIT)!=0) exploit(); if((tasks&CRACK)!=0) crack(); Logger.debug(target+" done"); synchronized (MultiAttackService.this) { completedTargets++; mBuilder.setContentInfo(String.format(Locale.getDefault(), "%d/%d", completedTargets, totalTargets)) .setChannelId(getBaseContext().getString(R.string.csploitChannelId)); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } } catch (InterruptedException e) { if(future != null && !future.isDone()) future.cancel(false); if(process != null && process.running) process.kill(); Logger.info(e.getMessage()); } }
/** * 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); } }
/** * if mContentIntent is null delete our notification, * else assign it to the notification onClick */ private void finishNotification() { boolean errorOccurred; Intent contentIntent; errorOccurred = mCurrentTask.errorOccurred; contentIntent = mCurrentTask.haveIntent() ? mCurrentTask.buildIntent() : null; if(errorOccurred || contentIntent==null){ Logger.debug("deleting notifications"); if(mNotificationManager!=null) mNotificationManager.cancel(NOTIFICATION_ID); } else { Logger.debug("assign '"+contentIntent.toString()+"' to notification"); if(mBuilder!=null&&mNotificationManager!=null) { mBuilder.setContentIntent(PendingIntent.getActivity(this, DOWNLOAD_COMPLETE_CODE, contentIntent, 0)) .setChannelId(getBaseContext().getString(R.string.csploitChannelId)); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } } if(mReceiver!=null) unregisterReceiver(mReceiver); mReceiver = null; mBuilder = null; mNotificationManager = null; }
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()); } }
/** * if mContentIntent is null delete our notification, * else assign it to the notification onClick */ private void finishNotification() { if(mContentIntent==null){ Logger.debug("deleting notifications"); mNotificationManager.cancel(NOTIFICATION_ID); } else { Logger.debug("assign '"+mContentIntent.toString()+"'to notification"); mBuilder.setContentIntent(PendingIntent.getActivity(this, CLICK_CODE, mContentIntent, 0)) .setProgress(0,0,false) .setAutoCancel(true) .setDeleteIntent(PendingIntent.getActivity(this, 0, new Intent(), 0)) .setChannelId(getBaseContext().getString(R.string.csploitChannelId)); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } if(mReceiver!=null) unregisterReceiver(mReceiver); mReceiver = null; mBuilder = null; mNotificationManager = null; }
/** * 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()); }