builder.setWhen(0) .setContentTitle(getResources().getString(R.string.notice_activated)) .setDefaults(NotificationCompat.DEFAULT_LIGHTS) .setSmallIcon(R.drawable.ic_security)
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); }
.addAction(R.drawable.ic_reject_pairing, res.getString(R.string.pairing_reject), rejectedPendingIntent) .setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .build();
getResources(), R.drawable.ic_alarm_white_48dp)) .setDefaults(NotificationCompat.DEFAULT_ALL)
R.drawable.ic_person_black_48dp)) .setContentIntent(mainPendingIntent) .setDefaults(NotificationCompat.DEFAULT_ALL)
R.drawable.ic_person_black_48dp)) .setContentIntent(mainPendingIntent) .setDefaults(NotificationCompat.DEFAULT_ALL)
getResources(), R.drawable.ic_person_black_48dp)) .setContentIntent(mainPendingIntent) .setDefaults(NotificationCompat.DEFAULT_ALL)
.setContentIntent(eventPendingIntent) .setAutoCancel(true) .setDefaults(defaultFlags) .setPriority(NotificationCompat.PRIORITY_HIGH) .setCategory(NotificationCompat.CATEGORY_EVENT)
R.drawable.ic_person_black_48dp)) .setContentIntent(mainPendingIntent) .setDefaults(NotificationCompat.DEFAULT_ALL)
R.drawable.ic_person_black_48dp)) .setContentIntent(mainPendingIntent) .setDefaults(NotificationCompat.DEFAULT_ALL)
notification.setVibrate(new long[]{0}); // a hack to get a headsup to show notification.setDefaults(defaults); synchronized (this) { NotificationManagerCompat.from(context).notify(mNotificationId, notification.build());
.setAutoCancel(true) .setLocalOnly(true) // to avoid bouncing the notification back to other kdeconnect nodes .setDefaults(Notification.DEFAULT_ALL) .setStyle(new NotificationCompat.BigTextStyle().bigText(np.getString("ticker"))) .build();
.setSmallIcon(R.drawable.ic_notification) .setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)) .build();
@TargetApi(Build.VERSION_CODES.N) private static void createSummaryGroupNotification( Context ctx, Account account, Set<String> notifications, boolean feedback) { int notificationId = FowlerNollVo.fnv1_32(account.getAccountHash().getBytes()).intValue(); NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx, account.getAccountHash()) .setContentTitle(getNotificationSubText(account)) .setSubText(getNotificationSubText(account)) .setSmallIcon(R.drawable.ic_stat_notify) .setAutoCancel(true) .setCategory(NotificationCompat.CATEGORY_SOCIAL) .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setDefaults(feedback ? NotificationCompat.DEFAULT_ALL : 0) .setColor(ContextCompat.getColor(ctx, R.color.primaryDark)) .setContentIntent( getViewAccountChangesPendingIntent(ctx, account, notificationId)) .setDeleteIntent( getDeleteAccountNotificationPendingIntent(ctx, account, notificationId)) .setOnlyAlertOnce(true) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC); NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle() .setSummaryText(getNotificationSubText(account)); builder.setStyle(style) .setNumber(notifications.size()) .setGroupSummary(true) .setGroup(NOTIFICATION_KEY_GROUP + account.getAccountHash()); publishNotification(ctx, builder.build(), notificationId); }
@RequiresApi(Build.VERSION_CODES.N) public void showNotificationGroup(long priority) { Intent intent = new Intent(this, MessagesActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder b = new NotificationCompat.Builder( this, NotificationSupport.convertPriorityToChannel(priority)); b.setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setWhen(System.currentTimeMillis()) .setSmallIcon(R.drawable.ic_gotify) .setTicker(getString(R.string.app_name)) .setGroup(NotificationSupport.Group.MESSAGES) .setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN) .setContentTitle(getString(R.string.grouped_notification_text)) .setGroupSummary(true) .setContentText(getString(R.string.grouped_notification_text)) .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary)) .setContentIntent(contentIntent); NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(-5, b.build()); } }
private void showNotification(int id, String title, String message, long priority) { Intent intent = new Intent(this, MessagesActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder b = new NotificationCompat.Builder( this, NotificationSupport.convertPriorityToChannel(priority)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { showNotificationGroup(priority); } b.setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setWhen(System.currentTimeMillis()) .setSmallIcon(R.drawable.ic_gotify) .setTicker(getString(R.string.app_name) + " - " + title) .setGroup(NotificationSupport.Group.MESSAGES) .setContentTitle(title) .setContentText(message) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND) .setLights(Color.CYAN, 1000, 5000) .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary)) .setContentIntent(contentIntent); NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(id, b.build()); }
private static NotificationCompat.Builder createNotificationBuilder( Context ctx, Account account, NotificationEntity entity, boolean feedback) { return new NotificationCompat.Builder(ctx, account.getAccountHash()) .setContentTitle(entity.mNotification.subject) .setContentText(getContentTitle(ctx, entity, true)) .setSubText(getNotificationSubText(account)) .setSmallIcon(R.drawable.ic_stat_notify) .setAutoCancel(true) .setCategory(NotificationCompat.CATEGORY_SOCIAL) .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setDefaults(feedback ? NotificationCompat.DEFAULT_ALL : 0) .setWhen(entity.mWhen) .setColor(ContextCompat.getColor(ctx, R.color.primaryDark)) .setContentIntent(getViewChangePendingIntent(ctx, entity)) .setDeleteIntent(getDeleteGroupNotificationPendingIntent(ctx, entity.mGroupId)) .setOnlyAlertOnce(true) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC); }
public static Notification getFTPRunning(Context context, String title, String text, PendingIntent intent) { NotificationCompat.Builder builder = new NotificationCompat.Builder(context, NotificationChannelHelper.getChannelLow(context)) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)) .setSmallIcon(R.drawable.ic_notification_ftp) .setColor(ContextCompat.getColor(context, R.color.colorPrimary)) .setDefaults(NotificationCompat.DEFAULT_ALL) .setCategory(NotificationCompat.CATEGORY_SERVICE) .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setVisibility(NotificationCompat.VISIBILITY_PRIVATE) .setAutoCancel(false) .setOngoing(true) .setContentTitle(title) .setContentText(text) .setContentIntent(intent); return builder.build(); } }
@Override public NotificationBuilder setDefaults(final int defaults) { super.setDefaults(defaults); return this; }
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); } }