@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); } };
/** * 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; }
.setContentText(getString(R.string.click_here_to_upgrade)) .setProgress(0, 0, false) // remove progress bar .setAutoCancel(true); exitForError=false; return true;
private void makeTorrentInfoNotify(String name, String message) { if (name == null || message == null) return; NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(), DEFAULT_CHAN_ID) .setSmallIcon(R.drawable.ic_info_white_24dp) .setColor(ContextCompat.getColor(getApplicationContext(), R.color.primary)) .setContentTitle(name) .setTicker(message) .setContentText(message) .setAutoCancel(true) .setWhen(System.currentTimeMillis()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) builder.setCategory(Notification.CATEGORY_STATUS); notifyManager.notify(name.hashCode(), builder.build()); }
static void showUpdateAvailableNotification(Context context, String title, String content, UpdateFrom updateFrom, URL apk, int smallIconResourceId) { PendingIntent contentIntent = PendingIntent.getActivity(context, 0, context.getPackageManager().getLaunchIntentForPackage(UtilsLibrary.getAppPackageName(context)), PendingIntent.FLAG_CANCEL_CURRENT); PendingIntent pendingIntentUpdate = PendingIntent.getActivity(context, 0, UtilsLibrary.intentToUpdate(context, updateFrom, apk), PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setContentIntent(contentIntent) .setContentTitle(title) .setContentText(content) .setStyle(new NotificationCompat.BigTextStyle().bigText(content)) .setSmallIcon(smallIconResourceId) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setOnlyAlertOnce(true) .setAutoCancel(true) .addAction(R.drawable.ic_system_update_white_24dp, context.getResources().getString(R.string.appupdater_btn_update), pendingIntentUpdate); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, builder.build()); }
private void makeNatErrorNotify(String message) { if (message == null) return; NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(), DEFAULT_CHAN_ID) .setSmallIcon(R.drawable.ic_error_white_24dp) .setColor(ContextCompat.getColor(getApplicationContext(), R.color.primary)) .setContentTitle(getString(R.string.nat_error_title)) .setTicker(getString(R.string.nat_error_title)) .setContentText(String.format(getString(R.string.error_template), message)) .setAutoCancel(true) .setWhen(System.currentTimeMillis()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) builder.setCategory(Notification.CATEGORY_ERROR); notifyManager.notify(NAT_ERROR_NOTIFICATION_ID, builder.build()); }
private void makeSessionErrorNotify(String message) { if (message == null) return; NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(), DEFAULT_CHAN_ID) .setSmallIcon(R.drawable.ic_error_white_24dp) .setColor(ContextCompat.getColor(getApplicationContext(), R.color.primary)) .setContentTitle(getString(R.string.session_error_title)) .setTicker(getString(R.string.session_error_title)) .setContentText(String.format(getString(R.string.error_template), message)) .setAutoCancel(true) .setWhen(System.currentTimeMillis()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) builder.setCategory(Notification.CATEGORY_ERROR); notifyManager.notify(SESSION_ERROR_NOTIFICATION_ID, builder.build()); }
private void makeTorrentAddedNotify(String name) { if (name == null) return; String title = getString(R.string.torrent_added_notify); NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(), DEFAULT_CHAN_ID) .setSmallIcon(R.drawable.ic_done_white_24dp) .setColor(ContextCompat.getColor(getApplicationContext(), R.color.primary)) .setContentTitle(title) .setTicker(title) .setContentText(name) .setAutoCancel(true) .setWhen(System.currentTimeMillis()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) builder.setCategory(Notification.CATEGORY_STATUS); notifyManager.notify(name.hashCode(), builder.build()); }
public void showAlarmNotification(Context context) { AlarmEntryReader reader = AlarmEntryReader.construct(context); String notifyText = reader.getNotificationText(); Intent notifyIntent = new Intent(context, MainActivity.class); PendingIntent notifyPendingIntent = PendingIntent.getActivity(context, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context); Notification notification = mBuilder.setSmallIcon(R.drawable.ic_launcher_openscale) .setContentTitle(context.getString(R.string.app_name)) .setContentText(notifyText) .setAutoCancel(true) .setContentIntent(notifyPendingIntent) .build(); NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE); mNotifyMgr.notify(ALARM_NOTIFICATION_ID, notification); }
public static void showNotification(Context context, String title, String content) { Intent intent = new Intent(context, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new NotificationCompat.Builder(context, MainActivity.EVENT_NOTIFICATION_ID) .setContentTitle(title) .setContentText(content) .setSmallIcon(R.drawable.ic_notification) .setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setContentIntent(pendingIntent) .build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; manager.notify(1, notification); }
static void showUpdateNotAvailableNotification(Context context, String title, String content, int smallIconResourceId) { PendingIntent contentIntent = PendingIntent.getActivity(context, 0, context.getPackageManager().getLaunchIntentForPackage(UtilsLibrary.getAppPackageName(context)), PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setContentIntent(contentIntent) .setContentTitle(title) .setContentText(content) .setStyle(new NotificationCompat.BigTextStyle().bigText(content)) .setSmallIcon(smallIconResourceId) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setOnlyAlertOnce(true) .setAutoCancel(true); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, builder.build()); }
private void doNotification(String contents) { if (n == null) { n = new NotificationCompat.Builder(this, AppNavHomeActivity.BOOT_CHANNEL_ID); } n.setStyle(new NotificationCompat.BigTextStyle().bigText(contents)) .setContentTitle(RunAtBootService.TAG) .setSmallIcon(R.drawable.ic_stat_ic_nh_notificaiton) .setAutoCancel(true); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); if (notificationManager != null) { notificationManager.notify(999, n.build()); } }
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 public NotificationBuilder setAutoCancel(final boolean autoCancel) { super.setAutoCancel(autoCancel); return this; }
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 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); } }
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); }
.setSmallIcon(R.drawable.ic_security) .setAutoCancel(false) .setOngoing(true) .setTicker(getResources().getString(R.string.notice_activated))
PendingIntent.FLAG_UPDATE_CURRENT )) .setAutoCancel(true) .build(); notificationManager.notify((int) deckId, notification);
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()); } }