@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)); mNotificationManager.notify(NOTIFICATION_ID,mBuilder.build()); .setChannelId(getBaseContext().getString(R.string.csploitChannelId)); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); mBuilder.setProgress(100, percentage, false) .setContentInfo(percentage + "%") .setChannelId(getBaseContext().getString(R.string.csploitChannelId)); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); previous_percentage = percentage;
@Override public NotificationBuilder setChannelId(@NonNull final String channelId) { super.setChannelId(channelId); mChannelBuilder.setId(channelId); return this; }
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. } }
.setSmallIcon(android.R.drawable.ic_popup_sync) .setProgress(100, 0, false) .setChannelId(getBaseContext().getString(R.string.csploitChannelId)); mNotificationManager.notify(NOTIFICATION_ID,mBuilder.build()); mBuilder.setProgress(100, percentage, false) .setContentInfo(percentage + "%") .setChannelId(getBaseContext().getString(R.string.csploitChannelId)); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); old_percentage = percentage; .setChannelId(getBaseContext().getString(R.string.csploitChannelId)); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } finally {
.setContentText("") .setProgress(100, 0, false) .setChannelId(getBaseContext().getString(R.string.csploitChannelId)); mNotificationManager.notify(NOTIFICATION_ID,mBuilder.build()); mBuilder.setProgress(100, percentage, false) .setContentInfo(percentage + "%") .setChannelId(getBaseContext().getString(R.string.csploitChannelId)); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); previous_percentage = percentage;
.setContentInfo("") .setProgress(100, 0, true) .setChannelId(getBaseContext().getString(R.string.csploitChannelId)); mNotificationManager.notify(NOTIFICATION_ID,mBuilder.build()); mBuilder.setProgress(100, percentage, false) .setContentInfo(percentage + "%") .setChannelId(getBaseContext().getString(R.string.csploitChannelId)); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); old_percentage = percentage;
.setSmallIcon(android.R.drawable.stat_sys_download) .setProgress(100, 0, true) .setChannelId(getBaseContext().getString(R.string.csploitChannelId)); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); Child bundleInstallTask; .setChannelId(getBaseContext().getString(R.string.csploitChannelId)); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
@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 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; }
/** * 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; }