List of usage examples for android.app Notification Notification
@Deprecated public Notification(int icon, CharSequence tickerText, long when)
From source file:com.jiee.smartplug.services.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./*from w w w. j a v a 2s . co m*/ */ private void sendNotification(String message) { System.out.println(message); NotificationManager notif = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Notification notify = new Notification(R.drawable.svc_0_small_off, "title", System.currentTimeMillis()); PendingIntent pending = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0); notify.setLatestEventInfo(getApplicationContext(), "Subject", message, pending); notif.notify(0, notify); // Intent intent = new Intent(this, MainActivity.class); // intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, // PendingIntent.FLAG_ONE_SHOT); // // Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); // NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) // .setSmallIcon(R.drawable.ic_stat_ic_notification) // .setContentTitle("GCM Message") // .setContentText(message) // .setAutoCancel(true) // .setSound(defaultSoundUri) // .setContentIntent(pendingIntent); // // NotificationManager notificationManager = // (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // // notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.ushahidi.android.app.BackgroundService.java
private void showNotification(String tickerText) { // This is what should be launched if the user selects our notification. Intent baseIntent = new Intent(this, IncidentTab.class); baseIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, baseIntent, 0); // choose the ticker text newUshahidiReportNotification = new Notification(R.drawable.notification_icon, tickerText, System.currentTimeMillis()); newUshahidiReportNotification.contentIntent = contentIntent; newUshahidiReportNotification.flags = Notification.FLAG_AUTO_CANCEL; newUshahidiReportNotification.defaults = Notification.DEFAULT_ALL; newUshahidiReportNotification.setLatestEventInfo(this, TAG, tickerText, contentIntent); if (Preferences.ringtone) { // set the ringer Uri ringURI = Uri.fromFile(new File("/system/media/audio/ringtones/ringer.mp3")); newUshahidiReportNotification.sound = ringURI; }//from w w w .j a v a2 s . co m if (Preferences.vibrate) { double vibrateLength = 100 * Math.exp(0.53 * 20); long[] vibrate = new long[] { 100, 100, (long) vibrateLength }; newUshahidiReportNotification.vibrate = vibrate; if (Preferences.flashLed) { int color = Color.BLUE; newUshahidiReportNotification.ledARGB = color; } newUshahidiReportNotification.ledOffMS = (int) vibrateLength; newUshahidiReportNotification.ledOnMS = (int) vibrateLength; newUshahidiReportNotification.flags = newUshahidiReportNotification.flags | Notification.FLAG_SHOW_LIGHTS; } mNotificationManager.notify(Preferences.NOTIFICATION_ID, newUshahidiReportNotification); }
From source file:com.ushahidi.android.app.UshahidiService.java
private void showNotification(String tickerText) { // This is what should be launched if the user selects our notification. Intent baseIntent = new Intent(this, IncidentsTab.class); baseIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, baseIntent, 0); // choose the ticker text newUshahidiReportNotification = new Notification(R.drawable.favicon, tickerText, System.currentTimeMillis()); newUshahidiReportNotification.contentIntent = contentIntent; newUshahidiReportNotification.flags = Notification.FLAG_AUTO_CANCEL; newUshahidiReportNotification.defaults = Notification.DEFAULT_ALL; newUshahidiReportNotification.setLatestEventInfo(this, TAG, tickerText, contentIntent); if (UshahidiPref.ringtone) { // set the ringer Uri ringURI = Uri.fromFile(new File("/system/media/audio/ringtones/ringer.mp3")); newUshahidiReportNotification.sound = ringURI; }// ww w .j a v a 2 s. c o m if (UshahidiPref.vibrate) { double vibrateLength = 100 * Math.exp(0.53 * 20); long[] vibrate = new long[] { 100, 100, (long) vibrateLength }; newUshahidiReportNotification.vibrate = vibrate; if (UshahidiPref.flashLed) { int color = Color.BLUE; newUshahidiReportNotification.ledARGB = color; } newUshahidiReportNotification.ledOffMS = (int) vibrateLength; newUshahidiReportNotification.ledOnMS = (int) vibrateLength; newUshahidiReportNotification.flags = newUshahidiReportNotification.flags | Notification.FLAG_SHOW_LIGHTS; } mNotificationManager.notify(UshahidiPref.NOTIFICATION_ID, newUshahidiReportNotification); }
From source file:com.akop.bach.service.XboxLiveServiceClient.java
private void notifyMessages(XboxLiveAccount account, long[] unreadMessages, List<Long> lastUnreadList) { NotificationManager mgr = getNotificationManager(); Context context = getContext(); int notificationId = 0x1000000 | ((int) account.getId() & 0xffffff); if (App.getConfig().logToConsole()) { String s = ""; for (Object unr : lastUnreadList) s += unr.toString() + ","; App.logv("Currently unread (%d): %s", lastUnreadList.size(), s); s = "";//w w w.jav a 2 s.c om for (Object unr : unreadMessages) s += unr.toString() + ","; App.logv("New unread (%d): %s", unreadMessages.length, s); } if (unreadMessages.length > 0) { int unreadCount = 0; for (Object unread : unreadMessages) { if (!lastUnreadList.contains(unread)) unreadCount++; } if (App.getConfig().logToConsole()) App.logv("%d computed new", unreadCount); if (unreadCount > 0) { String tickerTitle; String tickerText; if (unreadMessages.length == 1) { tickerTitle = context.getString(R.string.new_message); tickerText = context.getString(R.string.notify_message_pending_f, account.getScreenName(), Messages.getSender(context, unreadMessages[0])); } else { tickerTitle = context.getString(R.string.new_messages); tickerText = context.getString(R.string.notify_messages_pending_f, account.getScreenName(), unreadMessages.length, account.getDescription()); } Notification notification = new Notification(R.drawable.xbox_stat_notify_message, tickerText, System.currentTimeMillis()); Intent intent = new Intent(context, MessageList.class); intent.putExtra("account", account); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, 0); notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS; if (unreadMessages.length > 1) notification.number = unreadMessages.length; notification.ledOnMS = DEFAULT_LIGHTS_ON_MS; notification.ledOffMS = DEFAULT_LIGHTS_OFF_MS; notification.ledARGB = DEFAULT_LIGHTS_COLOR; notification.sound = account.getRingtoneUri(); if (account.isVibrationEnabled()) notification.defaults |= Notification.DEFAULT_VIBRATE; notification.setLatestEventInfo(context, tickerTitle, tickerText, contentIntent); mgr.notify(notificationId, notification); } } else // No unread messages { mgr.cancel(notificationId); } }
From source file:com.florianmski.tracktoid.trakt.tasks.get.UpdateShowsTask.java
private void createNotification() { notification = new Notification(R.drawable.ab_icon_refresh, "Refreshing...", System.currentTimeMillis()); nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); contentView = new RemoteViews(context.getPackageName(), R.layout.notification_progress); notification.contentView = contentView; Intent notificationIntent = new Intent(context, MyShowsActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.contentIntent = contentIntent; notification.flags = Notification.FLAG_NO_CLEAR; nm.notify(NOTIFICATION_ID, notification); }
From source file:net.bible.android.device.ProgressNotificationManager.java
/** find the Progress object in our map to the associated Notifications * // w w w . jav a 2 s .c om * @param prog * @return */ private Notification findOrCreateNotification(Progress prog) { Notification notification = progressMap.get(prog); if (notification == null) { Log.d(TAG, "Creating Notification for progress Hash:" + prog.hashCode()); // configure the intent Intent intent = new Intent(BibleApplication.getApplication(), ProgressStatus.class); final PendingIntent pendingIntent = PendingIntent.getActivity(BibleApplication.getApplication(), 0, intent, 0); notification = new Notification(R.drawable.bible, prog.getJobName(), System.currentTimeMillis()); notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT | Notification.FLAG_AUTO_CANCEL; notification.contentView = new RemoteViews(SharedConstants.PACKAGE_NAME, R.layout.progress_notification); notification.contentIntent = pendingIntent; notification.contentView.setImageViewResource(R.id.status_icon, R.drawable.bible); notification.contentView.setTextViewText(R.id.status_text, ""); notification.contentView.setProgressBar(R.id.status_progress, 100, prog.getWork(), false); progressMap.put(prog, notification); androidNotificationManager.notify(prog.hashCode(), notification); } return notification; }
From source file:net.bible.service.device.ProgressNotificationManager.java
/** find the Progress object in our map to the associated Notifications * /* w w w . j ava 2 s. c o m*/ * @param prog * @return */ private Notification findOrCreateNotification(Progress prog) { Notification notification = progressMap.get(prog); if (notification == null) { Log.d(TAG, "Creating Notification for progress Hash:" + prog.hashCode()); // configure the intent Intent intent = new Intent(BibleApplication.getApplication(), ProgressStatus.class); final PendingIntent pendingIntent = PendingIntent.getActivity(BibleApplication.getApplication(), 0, intent, 0); notification = new Notification(R.drawable.ic_stat_ichthys, prog.getJobName(), System.currentTimeMillis()); notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT | Notification.FLAG_AUTO_CANCEL; notification.contentView = new RemoteViews(SharedConstants.PACKAGE_NAME, R.layout.progress_notification); notification.contentIntent = pendingIntent; notification.contentView.setImageViewResource(R.id.status_icon, R.drawable.ichthys); notification.contentView.setTextViewText(R.id.status_text, ""); notification.contentView.setProgressBar(R.id.status_progress, 100, prog.getWork(), false); progressMap.put(prog, notification); androidNotificationManager.notify(prog.hashCode(), notification); } return notification; }
From source file:com.bellman.bible.service.device.ProgressNotificationManager.java
/** * find the Progress object in our map to the associated Notifications * * @param prog// w w w. jav a 2s.c o m * @return */ private Notification findOrCreateNotification(Progress prog) { Notification notification = progressMap.get(prog); if (notification == null) { Log.d(TAG, "Creating Notification for progress Hash:" + prog.hashCode()); // configure the intent Intent intent = new Intent(CurrentActivityHolder.getInstance().getApplication(), ProgressStatus.class); final PendingIntent pendingIntent = PendingIntent .getActivity(CurrentActivityHolder.getInstance().getApplication(), 0, intent, 0); notification = new Notification(R.drawable.ic_stat_ichthys, prog.getJobName(), System.currentTimeMillis()); notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT | Notification.FLAG_AUTO_CANCEL; notification.contentView = new RemoteViews(SharedConstants.PACKAGE_NAME, R.layout.progress_notification); notification.contentIntent = pendingIntent; notification.contentView.setImageViewResource(R.id.status_icon, R.drawable.ichthys); notification.contentView.setTextViewText(R.id.status_text, ""); notification.contentView.setProgressBar(R.id.status_progress, 100, prog.getWork(), false); progressMap.put(prog, notification); androidNotificationManager.notify(prog.hashCode(), notification); } return notification; }
From source file:com.cloverstudio.spika.GCMIntentService.java
@SuppressWarnings("deprecation") public void triggerNotification(Context context, String message, String fromName, Bundle pushExtras) { if (fromName != null) { final NotificationManager notificationManager = (NotificationManager) getSystemService( NOTIFICATION_SERVICE);//from w w w. j a v a 2 s . co m Notification notification = new Notification(R.drawable.icon_notification, message, System.currentTimeMillis()); notification.number = mNotificationCounter + 1; mNotificationCounter = mNotificationCounter + 1; Intent intent = new Intent(this, SplashScreenActivity.class); intent.replaceExtras(pushExtras); intent.putExtra(Const.PUSH_INTENT, true); intent.setAction(Long.toString(System.currentTimeMillis())); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_ACTIVITY_TASK_ON_HOME); PendingIntent pendingIntent = PendingIntent.getActivity(this, notification.number, intent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(this, context.getString(R.string.app_name), message, pendingIntent); notification.defaults |= Notification.DEFAULT_VIBRATE; notification.defaults |= Notification.DEFAULT_SOUND; notification.flags |= Notification.FLAG_AUTO_CANCEL; String notificationId = Double.toString(Math.random()); notificationManager.notify(notificationId, 0, notification); } }