Object notifSource = notification.getSource(); if (AdminDistributedSystemJmxImpl.NOTIF_MEMBER_JOINED.equals(notification.getType())) { ObjectName source = (ObjectName) notifSource; notification = new Notification(notification.getType(), notifSource, notificationSequenceNumber.addAndGet(1L), notification.getTimeStamp(), notification.getMessage());
private static Map buildOperationNotificationPacket(Notification note) { Map<String, Object> result = new HashMap<String, Object>(); result.put("event", note.getType()); result.put("source", note.getSource()); result.put("sequenceNumber", note.getSequenceNumber()); result.put("timeStamp", note.getTimeStamp()); result.put("data", note.getUserData()); return result; } }
/** * sendNotification * * @param eventType * @param data * @param msg */ public void sendNotification(String eventType, Object data, String msg) { Notification notif = new Notification(eventType, this, sequenceNumber .incrementAndGet(), System.currentTimeMillis(), msg); if (data != null) { notif.setUserData(data); } emitter.sendNotification(notif); }
/** * Replaces the notification source if necessary to do so. * From the {@link Notification javadoc}: * <i>"It is strongly recommended that notification senders use the object name * rather than a reference to the MBean object as the source."</i> * @param notification the {@link Notification} whose * {@link javax.management.Notification#getSource()} might need massaging */ private void replaceNotificationSourceIfNecessary(Notification notification) { if (notification.getSource() == null || notification.getSource().equals(this.managedResource)) { notification.setSource(this.objectName); } }
NotificationManager notificationManager = (NotificationManager) getSystemService(Service.NOTIFICATION_SERVICE); Notification notification = new Notification(/* your notification */); PendingIntent pendingIntent = /* your intent */; notification.setLatestEventInfo(this, /* your content */, pendingIntent); notificationManager.notify(/* id */, notification);
public void handleNotification(Notification notification, Object handback) { cat.debug("Received notification: "+notification.getType()); registerAppenderMBean((Appender) notification.getUserData() ); }
NotificationManager nm = (NotificationManager) getSystemService(context.NOTIFICATION_SERVICE); Notification notification = new Notification(); notification.flag = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR; Intent nIntent = new Intent(); nIntent = getPreviousIntent(); PendingIntent pi = PendingIntent.getActivity(this, 0, nIntent, 0); notification.setLatestEventInfo(getContext(), "some Title", "some text", pi); nm.notify(0,notification);
private static void generateNotification(Context context, String message) { int icon = R.drawable.ic_stat_gcm; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, MainActivity.class); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }
private static void generateNotification(Context context ,String name,String number) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); Intent notificationIntent = null; @SuppressWarnings("deprecation") Notification notification = new Notification(icon, "", when); NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); notificationIntent = new Intent(Intent.ACTION_DIAL); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); String p = "tel:" + number.trim(); notificationIntent.setData(Uri.parse(p)); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, "uPosi", "Callback Reminder from "+name, intent); // notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL; notification.sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.getPackageName() + "/raw/notification"); notification.defaults |= Notification.DEFAULT_VIBRATE; notificationManager.notify(generateUniqueId(), notification);
Notification notification = new Notification(icon, "Custom Notification", when); notification.contentView = contentView; Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.contentIntent = contentIntent; mNotificationManager.notify(1, notification);
protected void notifyJmx(String query, String type) { try { long sequence = notifySequence.incrementAndGet(); if (isNotifyPool()) { if (this.pool!=null && this.pool.getJmxPool()!=null) { this.pool.getJmxPool().notify(type, query); } } else { if (notifier!=null) { Notification notification = new Notification(type, this, sequence, System.currentTimeMillis(), query); notifier.sendNotification(notification); } } } catch (RuntimeOperationsException e) { if (log.isDebugEnabled()) { log.debug("Unable to send failed query notification.",e); } } }
public void broadcastLogEvent(final String event, final String[] throwableStringRep) { Notification notif = new Notification(LOGGING_EVENT_TYPE, this, sequenceNumber.incrementAndGet(), System.currentTimeMillis(), event); notif.setUserData(throwableStringRep); sendNotification(notif); notif = new Notification(notif.getType(), getClass().getName(), notif.getSequenceNumber(), notif.getTimeStamp(), notif.getMessage()); notif.setUserData(throwableStringRep); tcLoggingHistoryProvider.push(notif); }
Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, SnapClientActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, intent); notification.vibrate = new long[] { 500, 500 }; notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Notification.FLAG_SHOW_LIGHTS; notificationManager.notify(0, notification);
int notificationId = Integer.parseInt(intent.getData().getSchemeSpecificPart()); db = context.openOrCreateDatabase(DATABASE_NAME, SQLiteDatabase.CREATE_IF_NECESSARY, null); .getSystemService(Context.NOTIFICATION_SERVICE); long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); notification.defaults |= Notification.DEFAULT_SOUND; mNotificationManager.notify(1234, notification);
int icon = R.drawable.notification_icon; // icon from resources CharSequence tickerText = "Hello"; // ticker-text long when = System.currentTimeMillis(); // notification time Context context = getApplicationContext(); // application Context CharSequence contentTitle = "My notification"; // expanded message title CharSequence contentText = "Hello World!"; // expanded message text Intent notificationIntent = new Intent(this, MyClass.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); // the next two lines initialize the Notification, using the configurations above Notification notification = new Notification(icon, tickerText, when); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
@Override public void onReceive(Context context, Intent intent) { NotificationManager nm = (NotificationManager); context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(); notification.tickerText = "10 Minutes past"; nm.notify(0, notification); }
@Override public void progress(String tag, ProgressEvent event) { if (tag.startsWith("repair:")) { Optional<int[]> legacyUserData = getLegacyUserdata(tag, event); if (legacyUserData.isPresent()) { Notification jmxNotification = new Notification("repair", jmxObjectName, notificationSerialNumber.incrementAndGet(), event.getMessage()); jmxNotification.setUserData(legacyUserData.get()); broadcaster.sendNotification(jmxNotification); } } }
private void generateNotification(Context context, String message ) { int icon = R.drawable.icon; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message); String title = context.getString(R.string.app_name); Intent notificationIntent; notificationIntent = new Intent(context, ActivityName.class); notificationIntent.putExtra("From", "notifyFrag"); notificationIntent .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notificationIntent .setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_VIBRATE; notificationManager.notify(0, notification);
@Override protected void initInternal() throws LifecycleException { super.initInternal(); // Register the naming resources if (namingResources != null) { namingResources.init(); } // Send j2ee.object.created notification if (this.getObjectName() != null) { Notification notification = new Notification("j2ee.object.created", this.getObjectName(), sequenceNumber.getAndIncrement()); broadcaster.sendNotification(notification); } }
@Override protected void initInternal() throws LifecycleException { super.initInternal(); if (processTlds) { this.addLifecycleListener(new TldConfig()); } // Register the naming resources if (namingResources != null) { onameNamingResources = register(namingResources, "type=NamingResources," + getObjectNameKeyProperties()); } // Send j2ee.object.created notification if (this.getObjectName() != null) { Notification notification = new Notification("j2ee.object.created", this.getObjectName(), sequenceNumber.getAndIncrement()); broadcaster.sendNotification(notification); } }