public static Notification buildNotification(Context context, Notification.Builder builder) { builder.setSmallIcon(R.drawable.leak_canary_notification) .setWhen(System.currentTimeMillis()) .setOnlyAlertOnce(true); if (SDK_INT >= O) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationChannel notificationChannel = notificationManager.getNotificationChannel(NOTIFICATION_CHANNEL_ID); if (notificationChannel == null) { String channelName = context.getString(R.string.leak_canary_notification_channel); notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_DEFAULT); notificationManager.createNotificationChannel(notificationChannel); } builder.setChannelId(NOTIFICATION_CHANNEL_ID); } if (SDK_INT < JELLY_BEAN) { return builder.getNotification(); } else { return builder.build(); } }
Notification.Builder builder = new Notification.Builder(c) .setContentTitle("Notification Title") .setSmallIcon(R.drawable.ic_notification_icon) .setProgress(max_progress,current_progress,false) .setWhen(0); notification = builder.getNotification(); mNotificationManager.notify(NOTIFICATION_ID, notification);
.setDefaults(Notification.DEFAULT_SOUND); if (SDK_INT < JELLY_BEAN) { notification = builder.getNotification(); } else { notification = builder.build();
public static Notification buildNotification(Context context) { Notification.Builder builder = new Notification.Builder(context); builder.setContentText("service"); return builder.getNotification(); }
private void displayNotification(String data) { Notification.Builder nBuilder = new Notification.Builder(this) .setSmallIcon(R.drawable.ic_yubiclip) .setContentTitle(getString(R.string.app_name)) .setContentText(data); int nId = 0; NotificationManager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nManager.notify(nId, nBuilder.getNotification()); } }
private void updateNotification(String text) { contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, engine.getClass()), 0); Notification.Builder builder = new Notification.Builder(engine) .setContentTitle("WebServer") .setContentText(text) .setContentIntent(contentIntent) .setSmallIcon(R.mipmap.ic_launcher) .setWhen(System.currentTimeMillis()); notification = builder.getNotification(); notificationManager.notify(0, notification); }
@Override public Notification build(NotificationCompat2.Builder builder) { return createBuilder(builder).getNotification(); } }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private static void showNotificationFor11(Context context, Notification.Builder builder) { //noinspection deprecation getNotificationManager(context).notify(NOTIFICATION_ID, builder.getNotification()); }
Notification.Builder builder = new Notification.Builder(MyRemiderService.this); ..... builder.setSmallIcon(R.drawable. notification_template_icon_bg) .setContentTitle("ContentTitle") ..... .setContentIntent(pendingNotificationIntent); Notification notification = builder.getNotification(); notificationManager.notify(R.drawable.notification_template_icon_bg, notification);
private void showSendingNotification() { Notification.Builder builder = new Notification.Builder(this) .setTicker(getString(R.string.repost)) .setContentTitle(getString(R.string.wait_server_response)) .setNumber(100).setProgress(100, 100, false) .setOnlyAlertOnce(true).setOngoing(true).setSmallIcon(R.drawable.upload_white); Notification notification = builder.getNotification(); NotificationUtility.show(notification, R.string.repost); }
private void showSendingNotification() { Notification.Builder builder = new Notification.Builder(this) .setTicker(getString(R.string.sending)) .setContentTitle(getString(R.string.wait_server_response)) .setNumber(100).setProgress(100, 100, false) .setOnlyAlertOnce(true).setOngoing(true).setSmallIcon(R.drawable.upload_white); Notification notification = builder.getNotification(); NotificationUtility.show(notification, R.string.sending); }
Notification.Builder builder = new Notification.Builder(getApplicationContext()); builder.setSmallIcon(R.drawable.notification_icon); builder.setContentTitle("Your notification text"); builder.setProgress(100, 0, true); /* 0 out of 100 progress to start */ builder.setAutoCancel(false); builder.setOngoing(true); Notification notification = builder.getNotification(); /* NOTIFICATION_ID can just be a static int to identify your service's notification */ startForeground(NOTIFICATION_ID, notification);
Notification.Builder builder = new Notification.Builder(context); builder.setContentTitle("Your notification title"); builder.setContentText("Your notification text"); builder.setSmallIcon(R.drawable.ic_your_icon); builder.setContentIntent(yourIntent); notificationManager.notify(null, YOUR_UNIQUE_NOTIFICATION_ID, builder.getNotification());
/** * Retruns a new Notification. * * @param context the context to use. */ public Notification getNewNotification(Context context) { return getNewBuilder(context).getNotification(); // build() is API16. }
Notification.Builder builder = new Notification.Builder(MyRemiderService.this); ..... builder.setSmallIcon(R.drawable. notification_template_icon_bg) .setContentTitle("ContentTitle") ..... .setContentIntent(pendingNotificationIntent); Notification notification = builder.getNotification(); notificationManager.notify(R.drawable.notification_template_icon_bg, notification);
.setContentText(message) .setContentIntent(PendingIntent.getActivity(mContext, 0, new Intent(), 0)) .getNotification(); .setAutoCancel(true) .setStyle(new Notification.BigTextStyle().bigText(message)) .setContentIntent(pIntent).getNotification();
.setContentText(message) .setContentIntent(PendingIntent.getActivity(mContext, 0, new Intent(), 0)) .getNotification(); .setAutoCancel(true) .setStyle(new Notification.BigTextStyle().bigText(message)) .setContentIntent(pIntent).getNotification();
Notification.Builder builder = new Notification.Builder(ctx); @SuppressWarnings("deprecation") Notification notification=builder.getNotification(); notification.when=when; notification.tickerText=tickerText;
public class MyNotificationBuilderHoneyCombToIceCreamSandwich { Notification.Builder mb = null; MyNotificationBuilderHoneyCombToIceCreamSandwich(Context myContext, int icon, String ticker, String title, String info, Long timeStamp, PendingIntent pendingIntent, boolean onGoing) { mb = new Notification.Builder(myContext); mb.setSmallIcon(icon); mb.setContentIntent(pendingIntent); mb.setContentTitle(title); mb.setContentText(info); mb.setWhen(timeStamp); if (ticker != null) mb.setTicker(ticker); mb.setOngoing(onGoing); } Notification get() { return mb.getNotification(); } }
builder.build(); myNotication = builder.getNotification(); manager.notify(11, myNotication);