/** * Shows the notification with repost and discard options. Multiple Place-its listed as separate * notifications. */ public static void notify(final Context context, final int pID) { final Resources res = context.getResources(); PlaceIt placeIt = PlaceItList.find(pID); final String title = placeIt.getTitle(); // address for Categorical, Location cordinate for regular String address = placeIt.getDescription(); if (placeIt.getClass() == CategoricalPlaceIt.class) { address = ((CategoricalPlaceIt) placeIt).getAddress(); } else { address = "" + ((LocationPlaceIt) placeIt).getLocation().getLatitude() + ((LocationPlaceIt) placeIt).getLocation().getLongitude(); } final String fullTitle = res.getString(R.string.place_it_notification_title_template, title); final String fullAddress = res.getString(R.string.place_it_notification_text_template, address); final NotificationCompat.Builder notification = new NotificationCompat.Builder(context); // Set appropriate defaults for the notification light, sound, // and vibration. notification.setDefaults(Notification.DEFAULT_ALL); // required values notification.setSmallIcon(R.drawable.ic_launcher); notification.setContentTitle(fullTitle); notification.setContentText(fullAddress); // Set preview information for this notification. notification.setTicker(title); // On click action go to DescriptionActivity Intent descriptionIntent = new Intent(context, DescriptionActivity.class).putExtra(MainActivity.PLACEIT_ID, pID); notification.setContentIntent( PendingIntent.getActivity( context, pID, descriptionIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Repost action Intent repostIntent = new Intent(context, PlaceItNotification.class) .putExtra(BUTTON_TAG, R.string.notification_repost) .putExtra(MainActivity.PLACEIT_ID, pID); notification.addAction( R.drawable.ic_stat_repost, res.getString(R.string.notification_repost), PendingIntent.getBroadcast(context, 0, repostIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Discard action Intent discardIntent = new Intent(context, PlaceItNotification.class) .putExtra(BUTTON_TAG, R.string.notification_discard) .putExtra(MainActivity.PLACEIT_ID, pID); notification.addAction( R.drawable.ic_stat_discard, res.getString(R.string.notification_discard), PendingIntent.getBroadcast(context, 0, discardIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Automatically dismiss the notification when it is touched. notification.setAutoCancel(true); notify(context, notification.build(), pID); }