List of usage examples for android.app Notification setLatestEventInfo
@Deprecated public void setLatestEventInfo(Context context, CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent)
From source file:org.addhen.smssync.util.Util.java
/** * Show notification//w ww.java2s. c om */ public static void showNotification(Context context) { NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Intent baseIntent = new Intent(context, MessagesTabActivity.class); baseIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Notification notification = new Notification(R.drawable.icon, context.getString(R.string.status), System.currentTimeMillis()); notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR; PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, baseIntent, 0); notification.setLatestEventInfo(context, context.getString(R.string.app_name), context.getString(R.string.notification_summary), pendingIntent); notificationManager.notify(NOTIFY_RUNNING, notification); }
From source file:com.google.android.gms.common.GooglePlayServicesUtil.java
public static void showErrorNotification(int errorCode, Context context) { Resources resources = context.getResources(); Notification notification = new Notification(17301642, resources.getString(C0192R.string.common_google_play_services_notification_ticker), System.currentTimeMillis()); notification.flags |= 16;//w w w . j a va 2 s. co m CharSequence e = m116e(context, errorCode); String u = m119u(context); notification.setLatestEventInfo(context, e, resources.getString(C0192R.string.common_google_play_services_error_notification_requested_by_msg, new Object[] { u }), getErrorPendingIntent(errorCode, context, 0)); ((NotificationManager) context.getSystemService("notification")).notify(39789, notification); }
From source file:com.dmbstream.android.util.Util.java
/** * Resolves the default text color for notifications. * * Based on http://stackoverflow.com/questions/4867338/custom-notification-layouts-and-text-colors/7320604#7320604 *//* w w w . j a v a 2 s . co m*/ private static Pair<Integer, Integer> getNotificationTextColors(Context context) { if (NOTIFICATION_TEXT_COLORS.getFirst() == null && NOTIFICATION_TEXT_COLORS.getSecond() == null) { try { Notification notification = new Notification(); String title = "title"; String content = "content"; notification.setLatestEventInfo(context, title, content, null); LinearLayout group = new LinearLayout(context); ViewGroup event = (ViewGroup) notification.contentView.apply(context, group); findNotificationTextColors(event, title, content); group.removeAllViews(); } catch (Exception x) { Log.w(TAG, "Failed to resolve notification text colors.", x); } } return NOTIFICATION_TEXT_COLORS; }
From source file:com.andrewshu.android.reddit.common.Common.java
public static void newMailNotification(Context context, String mailNotificationStyle, int count) { Intent nIntent = new Intent(context, InboxActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, nIntent, 0); Notification notification = new Notification(R.drawable.mail, Constants.HAVE_MAIL_TICKER, System.currentTimeMillis()); if (Constants.PREF_MAIL_NOTIFICATION_STYLE_BIG_ENVELOPE.equals(mailNotificationStyle)) { RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.big_envelope_notification); notification.contentView = contentView; } else {//from w w w .j a v a2 s .c o m notification.setLatestEventInfo(context, Constants.HAVE_MAIL_TITLE, count + (count == 1 ? " unread message" : " unread messages"), contentIntent); } notification.defaults |= Notification.DEFAULT_SOUND; notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL; notification.contentIntent = contentIntent; NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(Constants.NOTIFICATION_HAVE_MAIL, notification); }
From source file:com.carpool.dj.carpool.model.GcmIntentService.java
/** * Issues a notification to inform the user that server has sent a message. */// w ww . j a v a 2 s . c om @SuppressWarnings("deprecation") private static void generateNotification(Context context, String message, Bundle data, String type) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // Notification notification = new Notification(icon, message, when); Notification notification = new Notification.Builder(context) .setContentTitle(Utils.nowActivity.getString(R.string.app_name)).setContentText(message) .setSmallIcon(icon).setWhen(when).setSound(alarmSound).build(); // String title = context.getString(R.string.app_name); Intent notificationIntent = null; if ("CarEvent".equals(type)) { notificationIntent = new Intent(context, ContentActivity.class); } else { return; } notificationIntent.putExtras(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, Utils.nowActivity.getString(R.string.app_name), message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }
From source file:pt.up.fe.cmov.propertymarket.C2DMReceiver.java
@Override protected void onMessage(Context context, Intent intent) { mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); int icon = R.drawable.icon; String type = intent.getStringExtra(C2DM_DATA_TYPE); String name = intent.getStringExtra(C2DM_DATA_NAME); String city = intent.getStringExtra(C2DM_DATA_CITY); int id = Integer.parseInt(intent.getStringExtra(C2DM_DATA_ID)); int price = Integer.parseInt(intent.getStringExtra(C2DM_DATA_PRICE)); String status = intent.getStringExtra(C2DM_DATA_NUM) + " props!"; String title = city + " - " + price + ""; String message = name + " is now available in Property Market!"; if (type.equals("apartment")) icon = R.drawable.apartment_icon; else if (type.equals("castle")) icon = R.drawable.castle_icon;//from w ww .j av a 2 s . c o m else if (type.equals("home")) icon = R.drawable.home_icon; PropertyMarketActivity.selectedPropertyID = id; Intent viewIntent = new Intent(this, PropertyTabMenuActivity.class); viewIntent.putExtra("yourpackage.notifyId", id); PendingIntent contentIntent = PendingIntent.getActivity(this, 1, viewIntent, 0); Notification notification = new Notification(icon, status, System.currentTimeMillis()); notification.setLatestEventInfo(this, title, message, contentIntent); mManager.notify(APP_ID, notification); }
From source file:com.google.android.apps.chrometophone.C2DMReceiver.java
private void generateNotification(Context context, String msg, String title, Intent intent) { int icon = R.drawable.status_icon; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, title, when); notification.setLatestEventInfo(context, title, msg, PendingIntent.getActivity(context, 0, intent, 0)); notification.defaults = Notification.DEFAULT_SOUND; notification.flags |= Notification.FLAG_AUTO_CANCEL; SharedPreferences settings = Prefs.get(context); int notificatonID = settings.getInt("notificationID", 0); // allow multiple notifications NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(notificatonID, notification); SharedPreferences.Editor editor = settings.edit(); editor.putInt("notificationID", ++notificatonID % 32); editor.commit();//from w ww . java2 s . c om }
From source file:com.ta.truckmap.gpstracking.GcmIntentService.java
@SuppressWarnings("deprecation") private Notification createNotificationConstraints(PendingIntent contentIntent, int type) { Notification notification = new Notification(R.drawable.appicon, TAG, System.currentTimeMillis()); notification.setLatestEventInfo(this, getResources().getString(R.string.app_name), myMsg, contentIntent); notification.defaults |= Notification.DEFAULT_SOUND; long[] vibrate = { 0, 100, 200, 300 }; notification.vibrate = vibrate;//from ww w. java 2 s . c o m notification.defaults |= Notification.DEFAULT_LIGHTS; notification.flags |= Notification.FLAG_AUTO_CANCEL; return notification; }
From source file:com.freshplanet.nativeExtensions.C2DMBroadcastReceiver.java
private void extractColors(Context context) { if (notification_text_color != null) return;//from w w w . ja va 2s. com try { Notification ntf = new Notification(); ntf.setLatestEventInfo(context, COLOR_SEARCH_RECURSE_TIP, "Utest", null); LinearLayout group = new LinearLayout(context); ViewGroup event = (ViewGroup) ntf.contentView.apply(context, group); recurseGroup(context, event); group.removeAllViews(); } catch (Exception e) { notification_text_color = android.R.color.black; } }
From source file:saphion.fragment.alarm.alert.AlarmAlertReceiver.java
@SuppressWarnings("deprecation") @Override/* w ww . j a va2 s . c o m*/ public void onReceive(final Context context, final Intent intent) { String action = intent.getAction(); int pos = intent.getIntExtra(PreferenceHelper.BAT_VALS, 0); level = intent.getIntExtra(PreferenceHelper.CURR_RING, 72); //Log.Toast(context, level + " in receiver", Toast.LENGTH_LONG); // int id = intent.getIntExtra(Intents.EXTRA_ID, -1); if (action.equals(Intents.ALARM_ALERT_ACTION)) { /* Close dialogs and window shade */ Intent closeDialogs = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); context.sendBroadcast(closeDialogs); // Decide which activity to start based on the state of the // keyguard. /* * KeyguardManager km = (KeyguardManager) * context.getSystemService(Context.KEYGUARD_SERVICE); if * (km.inKeyguardRestrictedInputMode()) { // Use the full screen * activity for security. c = AlarmAlertFullScreen.class; } */ // Trigger a notification that, when clicked, will show the alarm // alert // dialog. No need to check for fullscreen since this will always be // launched from a user action. if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { Intent notify = new Intent(context, saphion.fragments.alarm.AlarmAlert.class); notify.putExtra(PreferenceHelper.BAT_VALS, pos); PendingIntent pendingNotify = PendingIntent.getActivity(context, ID, notify, 0); // Alarm alarm = AlarmsManager.getAlarmsManager().getAlarm(id); Notification n = new Notification(R.drawable.stat_notify_alarm, "abc", System.currentTimeMillis()); n.setLatestEventInfo(context, "Battery Alarm", "Battery Level is " + level, pendingNotify); n.flags |= Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_ONGOING_EVENT; n.defaults |= Notification.DEFAULT_LIGHTS; // NEW: Embed the full-screen UI here. The notification manager // will // take care of displaying it if it's OK to do so. Intent alarmAlert = new Intent(context, saphion.fragments.alarm.AlarmAlert.class); alarmAlert.putExtra(PreferenceHelper.CURR_RING, level); alarmAlert.putExtra(PreferenceHelper.BAT_VALS, pos); alarmAlert.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION); n.fullScreenIntent = PendingIntent.getActivity(context, ID, alarmAlert, 0); // Send the notification using the alarm id to easily identify // the // correct notification. NotificationManager nm = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // Log.Toast(context, "Recieved", Toast.LENGTH_LONG); // mNotificationManager.notify(ID, builder.build()); nm.notify(ID, n); } else { // Log.Toast(context, "Recieved", Toast.LENGTH_LONG); newMethod(context, pos); } } else if (action.equals(Intents.ALARM_DISMISS_ACTION)) { NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(ID); } }