List of usage examples for android.app NotificationManager notify
public void notify(int id, Notification notification)
From source file:be.ac.ucl.lfsab1509.llncampus.ADE.java
/** * Start information update from ADE.//from w w w .j av a 2 s. c o m * * @param sa * Activity that launches the update thread. * @param updateRunnable * Runnable that launches the display update. * @param handler * Handler to allow the display update at the end of the execution. */ public static void runUpdateADE(final ScheduleActivity sa, final Handler handler, final Runnable updateRunnable) { final Resources r = sa.getResources(); final NotificationManager nm = (NotificationManager) sa.getSystemService(Context.NOTIFICATION_SERVICE); final NotificationCompat.Builder nb = new NotificationCompat.Builder(sa) .setSmallIcon(android.R.drawable.stat_sys_download) .setContentTitle(r.getString(R.string.download_from_ADE)) .setContentText(r.getString(R.string.download_progress)).setAutoCancel(true); final NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(r.getString(R.string.download_from_ADE)); nm.notify(NOTIFY_ID, nb.build()); new Thread(new Runnable() { @Override public void run() { /* * Fetching of code of courses to load. */ ArrayList<Course> courses = Course.getList(); if (courses == null || courses.isEmpty()) { // Take the context of the ScheduleActivity SharedPreferences preferences = new SecurePreferences(sa); String username = preferences.getString("username", null); String password = preferences.getString("password", null); if (username != null && password != null) { UCLouvain.downloadCoursesFromUCLouvain(sa, username, password, new Runnable() { public void run() { runUpdateADE(sa, handler, updateRunnable); } }, handler); } } /* * Number of weeks. To download all the schedule, the numbers go from 0 to 51 * (0 = beginning of first semester, 51 = ending of the September exams session). */ String weeks = getWeeks(); /* * Fetching data from ADE and updating the database */ int nbError = 0; int i = 0; ArrayList<Event> events; for (Course course : courses) { i++; nb.setProgress(courses.size(), i, false); nb.setContentText(r.getString(R.string.download_for) + " " + course.getCourseCode() + "..."); nm.notify(NOTIFY_ID, nb.build()); events = ADE.getInfo(course.getCourseCode(), weeks); if (events == null) { nbError++; inboxStyle.addLine(course.getCourseCode() + " : " + r.getString(R.string.download_error)); } else { // Removing old data LLNCampus.getDatabase().delete("Horaire", "COURSE = ?", new String[] { course.getCourseCode() }); // Adding new data for (Event e : events) { ContentValues cv = e.toContentValues(); cv.put("COURSE", course.getCourseCode()); if (LLNCampus.getDatabase().insert("Horaire", cv) < 0) { nbError++; } } inboxStyle.addLine(course.getCourseCode() + " : " + events.size() + " " + r.getString(R.string.events)); nb.setStyle(inboxStyle); } } nb.setProgress(courses.size(), courses.size(), false); if (nbError == 0) { nb.setContentText(r.getString(R.string.download_done)); inboxStyle.setBigContentTitle(r.getString(R.string.download_done)); nb.setSmallIcon(android.R.drawable.stat_sys_download_done); nb.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } else { nb.setContentText(r.getString(R.string.download_done) + ". " + r.getString(R.string.nb_error) + nbError + " :/"); inboxStyle.setBigContentTitle(r.getString(R.string.download_done) + ". " + r.getString(R.string.nb_error) + nbError + " :/"); nb.setSmallIcon(android.R.drawable.stat_notify_error); nb.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } nb.setStyle(inboxStyle); nm.notify(NOTIFY_ID, nb.build()); handler.post(updateRunnable); } }).start(); }
From source file:com.dmbstream.android.util.Util.java
private static void startForeground(Service service, int notificationId, Notification notification) { // Service.startForeground() was introduced in Android 2.0. // Use reflection to maintain compatibility with 1.5. try {// ww w .ja v a2 s. c o m Method method = Service.class.getMethod("startForeground", int.class, Notification.class); method.invoke(service, notificationId, notification); Log.i(TAG, "Successfully invoked Service.startForeground()"); } catch (Throwable x) { NotificationManager notificationManager = (NotificationManager) service .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(Constants.NOTIFICATION_ID_PLAYING, notification); Log.i(TAG, "Service.startForeground() not available. Using work-around."); } }
From source file:com.afrolkin.samplepushclient.GCMIntentService.java
private static void generateNotification(Context context, String message) { int icon = R.mipmap.ic_announcement_black_48dp; long when = System.currentTimeMillis(); String title = context.getString(R.string.app_name); Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, "Push Message", when); notification.sound = soundUri;/* w w w . ja v a2 s . c o m*/ Intent notificationIntent = new Intent(context, MainActivity.class); notificationIntent.putExtra("message", message); // 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, PendingIntent.FLAG_CANCEL_CURRENT); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }
From source file:com.android.mail.utils.NotificationActionUtils.java
/** * Creates and displays an Undo notification for the specified {@link NotificationAction}. *///w ww . j av a2 s. c o m public static void createUndoNotification(final Context context, final NotificationAction notificationAction) { LogUtils.i(LOG_TAG, "createUndoNotification for %s", notificationAction.getNotificationActionType()); final int notificationId = NotificationUtils.getNotificationId( notificationAction.getAccount().getAccountManagerAccount(), notificationAction.getFolder()); final Notification notification = createUndoNotification(context, notificationAction, notificationId); final NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(notificationId, notification); sUndoNotifications.put(notificationId, notificationAction); sNotificationTimestamps.put(notificationId, notificationAction.getWhen()); }
From source file:net.ben.subsonic.androidapp.util.Util.java
public static void showPlayingNotification(final Context context, Handler handler, MusicDirectory.Entry song) { // Use the same text for the ticker and the expanded notification String title = song.getTitle(); // Set the icon, scrolling text and timestamp final Notification notification = new Notification(R.drawable.stat_notify_playing, title, System.currentTimeMillis()); notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; // The PendingIntent to launch our activity if the user selects this notification PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, FragActivity.class), 0);//ww w . j a v a 2s . c o m String text = song.getArtist(); notification.setLatestEventInfo(context, title, text, contentIntent); // Send the notification. handler.post(new Runnable() { @Override public void run() { NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(Constants.NOTIFICATION_ID_PLAYING, notification); } }); // Update widget DownloadService service = DownloadServiceImpl.getInstance(); if (service != null) { SubsonicAppWidgetProvider.getInstance().notifyChange(context, service, true); } }
From source file:com.arisprung.tailgate.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *///from ww w . ja va 2s. c om private static void generateNotification(Context context, MessageBean message) { // Intent notificationIntent = new Intent(ctx, MainActivity.class); // PendingIntent contentIntent = PendingIntent.getActivity(ctx, // 10, notificationIntent, // PendingIntent.FLAG_CANCEL_CURRENT); // // NotificationManager nm = (NotificationManager) ctx // .getSystemService(Context.NOTIFICATION_SERVICE); // // Resources res = ctx.getResources(); // Notification.Builder builder = new Notification.Builder(ctx); // // Bitmap profile = TailGateUtility.getUserPic(message.getFaceID()); // // builder.setContentIntent(contentIntent) // .setSmallIcon(R.drawable.ic_launcher) // .setLargeIcon(profile) // .setTicker(res.getString(R.string.app_name)) // .setWhen(System.currentTimeMillis()) // .setAutoCancel(true) // .setContentTitle(message.getUserName()) // .setContentText(message.getMessage()); // Notification n = builder.build(); // // nm.notify(0, n); int icon = R.drawable.fanatic_icon_72px; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message.getMessage(), when); String name = message.getUserName(); 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, name, message.getMessage(), intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }
From source file:com.fanfou.app.opensource.service.DownloadService.java
public static void notifyUpdate(final AppVersionInfo info, final Context context) { final String versionInfo = info.versionName; final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); final Notification notification = new Notification(R.drawable.ic_notify_icon, "?" + versionInfo, System.currentTimeMillis()); final PendingIntent contentIntent = PendingIntent.getActivity(context, 0, DownloadService.getNewVersionIntent(context, info), 0); notification.setLatestEventInfo(context, "?" + versionInfo, "", contentIntent); notification.flags |= Notification.FLAG_AUTO_CANCEL; nm.notify(2, notification); }
From source file:com.appzoneltd.lastmile.customer.deprecated.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *///from www .jav a 2 s . c om private static void generateNotification(Context context, String message) { NotificationCompat.Builder notification; String title = context.getString(R.string.app_name); long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notification = new NotificationCompat.Builder(context); notification.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)); notification.setSmallIcon(R.mipmap.ic_launcher); notification.setContentTitle(title); notification.setContentText(message); Intent notificationIntent = new Intent(context, PushNotificationActivity.class); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setContentIntent(intent); notification.setAutoCancel(true); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); notificationManager.notify(1, notification.build()); }
From source file:com.anysoftkeyboard.ui.tutorials.TutorialsProvider.java
public static void showDragonsIfNeeded(Context context) { if (BuildConfig.TESTING_BUILD && firstTestersTimeVersionLoaded(context)) { Logger.i(TAG, "TESTERS VERSION added"); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, TestersNoticeActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0); final NotificationManager manager = ((NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE)); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context); notificationBuilder/* w w w. j a va2 s. co m*/ .setSmallIcon(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ? R.drawable.notification_icon_beta_version : R.drawable.ic_notification_debug_version) .setContentText(context.getText(R.string.notification_text_testers)) .setContentTitle(context.getText(R.string.ime_name_beta)).setWhen(System.currentTimeMillis()) .setContentIntent(contentIntent) .setColor(ContextCompat.getColor(context, R.color.notification_background_debug_version)) .setDefaults(0/*no sound, vibrate, etc*/).setAutoCancel(true); manager.notify(R.id.notification_icon_debug_version, notificationBuilder.build()); } }
From source file:com.google.android.gcm.demo.app.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//*from w w w .j a v a2 s . c om*/ private static void generateNotification(Context context, String message, String data) { int icon = R.drawable.ic_stat_gcm; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(0); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, DemoActivity.class); notificationIntent.putExtra(CommonUtilities.EXTRA_TEAM_IN_JSON, data); // 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, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, title, message, intent); notification.flags = Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }