Java Code Examples for android.support.v4.app.NotificationCompat.Builder#addAction()
The following examples show how to use
android.support.v4.app.NotificationCompat.Builder#addAction() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Notifications.java From Onosendai with Apache License 2.0 | 5 votes |
private static void updateColumn (final Context context, final DbInterface db, final Set<Integer> columnsHidingRetweets, final Column col, final NotificationManager nm) { final int nId = idForColumn(col); final int count = db.getUnreadCount(col, columnsHidingRetweets); if (count > 0) { final Intent showMainActI = new Intent(context, MainActivity.class) .setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP) .putExtra(MainActivity.ARG_FOCUS_COLUMN_ID, col.getId()); final PendingIntent showMainActPi = PendingIntent.getActivity(context, col.getId(), showMainActI, PendingIntent.FLAG_CANCEL_CURRENT); final List<Tweet> tweets = db.getTweets(col.getId(), Math.min(count, 5), Selection.FILTERED, col.getExcludeColumnIds(), columnsHidingRetweets, col.getInlineMediaStyle() == InlineMediaStyle.SEAMLESS, col.getNotificationStyle().isExcludeRetweets(), !col.getNotificationStyle().isIncludeOwnTweets()); final String msg = makeMsg(col, tweets, count); final Style style = makePreview(tweets, count); final PendingIntent markAsReadPi = MarkAsReadReceiver.makePi(context, col, tweets); final Builder nb = new NotificationCompat.Builder(context) .setOnlyAlertOnce(true) .setSmallIcon(notificationIcon()) .setContentTitle(col.getTitle()) .setContentText(msg) .setTicker(msg) .setNumber(count) .setContentIntent(showMainActPi) .setAutoCancel(true) .setWhen(System.currentTimeMillis()) .setStyle(style); if (markAsReadPi != null) nb.addAction(android.R.drawable.ic_menu_close_clear_cancel, "Mark as read", markAsReadPi); //ES applyStyle(nb, col.getNotificationStyle()); nm.notify(nId, nb.build()); } else { nm.cancel(nId); } }
Example 2
Source File: AlarmAlertReceiver.java From OmniList with GNU Affero General Public License v3.0 | 4 votes |
private void onAlert(Alarm alarm) { int alarmCode = (int) alarm.getCode(); Assignment assignment = AssignmentsStore.getInstance().get(alarm.getModelCode()); /*If the assignment is null, we don't show notification for it*/ if (assignment == null) { alarmsManager.removeAlarm(alarm); return; } Builder mBuilder = new Builder(context) .setContentTitle(assignment.getName()) .setContentText(assignment.getComment()) .setAutoCancel(true) .setSmallIcon(R.drawable.ic_assignment_turned_in_black_24dp) .setColor(ColorUtils.accentColor()); /*Add action: mark as done.*/ Intent mdIntent = new Intent(context, AlarmAlertReceiver.class); mdIntent.setAction(Constants.ACTION_MARK_ASSIGNMENT_AS_DONE); mdIntent.putExtra(Constants.EXTRA_CODE, assignment.getCode()); mdIntent.putExtra(Constants.EXTRA_NOTIFICATION_ID, (int) alarm.getCode()); PendingIntent piMD = PendingIntent.getBroadcast( context, (int) alarm.getCode(), mdIntent, PendingIntent.FLAG_CANCEL_CURRENT); mBuilder.addAction(R.drawable.ic_check_circle_black_24dp, context.getString(R.string.mark_as_done), piMD); /*Add action: postpone.*/ Intent pIntent = new Intent(context, AlarmAlertReceiver.class); pIntent.setAction(Constants.ACTION_POSTPONE_ALARM); pIntent.putExtra(Constants.EXTRA_CODE, alarm.getCode()); pIntent.putExtra(Constants.EXTRA_NOTIFICATION_ID, (int) alarm.getCode()); PendingIntent piP = PendingIntent.getBroadcast( context, (int) alarm.getCode(), pIntent, PendingIntent.FLAG_UPDATE_CURRENT); int snoozeMinutes = NoticePreferences.getInstance().getSnoozeDuration(); mBuilder.addAction(R.drawable.ic_snooze_black_24dp, String.format(context.getString(R.string.remind_in_minutes), snoozeMinutes), piP); /*Add action: click.*/ Intent clickIntent = new Intent(context, ContentActivity.class); clickIntent.setAction(Constants.ACTION_NOTIFICATION); clickIntent.putExtra(Constants.EXTRA_CODE, assignment.getCode()); clickIntent.putExtra(Constants.EXTRA_FRAGMENT, Constants.VALUE_FRAGMENT_ASSIGNMENT); clickIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent contentIntent = PendingIntent.getActivity( context, (int) assignment.getCode(), clickIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(contentIntent); /*Vibrate.*/ if (NoticePreferences.getInstance().isVibrateAllowed()) { mBuilder.setVibrate(getVibrate()); } /*Ringtone.*/ String ringtone = NoticePreferences.getInstance().getNotificationRingtone(); // 铃声 if (ringtone != null){ mBuilder.setSound(Uri.parse(ringtone)); } Notification notification = mBuilder.build(); /*Light.*/ setNotificationLight(notification); notificationManager.notify(alarmCode, notification); }