List of usage examples for android.app Notification DEFAULT_SOUND
int DEFAULT_SOUND
To view the source code for android.app Notification DEFAULT_SOUND.
Click Source Link
From source file:com.google.samples.apps.sergio.service.SessionAlarmService.java
private void notifySessionFeedback(boolean debug) { LOGD(TAG, "Considering firing notification for session feedback."); if (debug) {// www . j a v a 2s.com LOGD(TAG, "Note: this is a debug notification."); } // Don't fire notification if this feature is disabled in settings if (!PrefUtils.shouldShowSessionFeedbackReminders(this)) { LOGD(TAG, "Skipping session feedback notification. Disabled in settings."); return; } final Cursor c = getContentResolver().query(ScheduleContract.Sessions.CONTENT_MY_SCHEDULE_URI, SessionsNeedingFeedbackQuery.PROJECTION, SessionsNeedingFeedbackQuery.WHERE_CLAUSE, null, null); if (c == null) { return; } List<String> needFeedbackIds = new ArrayList<String>(); List<String> needFeedbackTitles = new ArrayList<String>(); while (c.moveToNext()) { String sessionId = c.getString(SessionsNeedingFeedbackQuery.SESSION_ID); String sessionTitle = c.getString(SessionsNeedingFeedbackQuery.SESSION_TITLE); // Avoid repeated notifications. if (UIUtils.isFeedbackNotificationFiredForSession(this, sessionId)) { LOGD(TAG, "Skipping repeated session feedback notification for session '" + sessionTitle + "'"); continue; } needFeedbackIds.add(sessionId); needFeedbackTitles.add(sessionTitle); } if (needFeedbackIds.size() == 0) { // the user has already been notified of all sessions needing feedback return; } LOGD(TAG, "Going forward with session feedback notification for " + needFeedbackIds.size() + " session(s)."); final Resources res = getResources(); // this is used to synchronize deletion of notifications on phone and wear Intent dismissalIntent = new Intent(ACTION_NOTIFICATION_DISMISSAL); // TODO: fix Wear dismiss integration //dismissalIntent.putExtra(KEY_SESSION_ID, sessionId); PendingIntent dismissalPendingIntent = PendingIntent.getService(this, (int) new Date().getTime(), dismissalIntent, PendingIntent.FLAG_UPDATE_CURRENT); String provideFeedbackTicker = res.getString(R.string.session_feedback_notification_ticker); NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this) .setColor(getResources().getColor(R.color.theme_primary)).setContentText(provideFeedbackTicker) .setTicker(provideFeedbackTicker) .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR, SessionAlarmService.NOTIFICATION_LED_ON_MS, SessionAlarmService.NOTIFICATION_LED_OFF_MS) .setSmallIcon(R.drawable.ic_stat_notification).setPriority(Notification.PRIORITY_LOW) .setLocalOnly(true) // make it local to the phone .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setDeleteIntent(dismissalPendingIntent).setAutoCancel(true); if (needFeedbackIds.size() == 1) { // Only 1 session needs feedback Uri sessionUri = ScheduleContract.Sessions.buildSessionUri(needFeedbackIds.get(0)); PendingIntent pi = TaskStackBuilder.create(this) .addNextIntent(new Intent(this, MyScheduleActivity.class)) .addNextIntent(new Intent(Intent.ACTION_VIEW, sessionUri, this, SessionFeedbackActivity.class)) .getPendingIntent(1, PendingIntent.FLAG_CANCEL_CURRENT); notifBuilder.setContentTitle(needFeedbackTitles.get(0)).setContentIntent(pi); } else { // Show information about several sessions that need feedback PendingIntent pi = TaskStackBuilder.create(this) .addNextIntent(new Intent(this, MyScheduleActivity.class)) .getPendingIntent(1, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(provideFeedbackTicker); for (String title : needFeedbackTitles) { inboxStyle.addLine(title); } notifBuilder .setContentTitle(getResources().getQuantityString(R.plurals.session_plurals, needFeedbackIds.size(), needFeedbackIds.size())) .setStyle(inboxStyle).setContentIntent(pi); } NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); LOGD(TAG, "Now showing session feedback notification!"); nm.notify(FEEDBACK_NOTIFICATION_ID, notifBuilder.build()); for (int i = 0; i < needFeedbackIds.size(); i++) { setupNotificationOnWear(needFeedbackIds.get(i), null, needFeedbackTitles.get(i), null); } }
From source file:com.jjcamera.apps.iosched.service.SessionAlarmService.java
/** * A starred session is about to end. Notify the user to provide session feedback. * Constructs and triggers a system notification. Does nothing if the session has already * concluded.//from w w w . j a va 2 s.co m */ private void notifySessionFeedback(boolean debug) { LOGD(TAG, "Considering firing notification for session feedback."); if (debug) { LOGW(TAG, "Note: this is a debug notification."); } // Don't fire notification if this feature is disabled in settings if (!SettingsUtils.shouldShowSessionFeedbackReminders(this)) { LOGD(TAG, "Skipping session feedback notification. Disabled in settings."); return; } Cursor c = null; try { c = getContentResolver().query(ScheduleContract.Sessions.CONTENT_MY_SCHEDULE_URI, SessionsNeedingFeedbackQuery.PROJECTION, SessionsNeedingFeedbackQuery.WHERE_CLAUSE, null, null); if (c == null) { return; } FeedbackHelper feedbackHelper = new FeedbackHelper(this); List<String> needFeedbackIds = new ArrayList<String>(); List<String> needFeedbackTitles = new ArrayList<String>(); while (c.moveToNext()) { String sessionId = c.getString(SessionsNeedingFeedbackQuery.SESSION_ID); String sessionTitle = c.getString(SessionsNeedingFeedbackQuery.SESSION_TITLE); // Avoid repeated notifications. if (feedbackHelper.isFeedbackNotificationFiredForSession(sessionId)) { LOGD(TAG, "Skipping repeated session feedback notification for session '" + sessionTitle + "'"); continue; } needFeedbackIds.add(sessionId); needFeedbackTitles.add(sessionTitle); } if (needFeedbackIds.size() == 0) { // the user has already been notified of all sessions needing feedback return; } LOGD(TAG, "Going forward with session feedback notification for " + needFeedbackIds.size() + " session(s)."); final Resources res = getResources(); // this is used to synchronize deletion of notifications on phone and wear Intent dismissalIntent = new Intent(ACTION_NOTIFICATION_DISMISSAL); // TODO: fix Wear dismiss integration //dismissalIntent.putExtra(KEY_SESSION_ID, sessionId); PendingIntent dismissalPendingIntent = PendingIntent.getService(this, (int) new Date().getTime(), dismissalIntent, PendingIntent.FLAG_UPDATE_CURRENT); String provideFeedbackTicker = res.getString(R.string.session_feedback_notification_ticker); NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this) .setColor(getResources().getColor(R.color.theme_primary)).setContentText(provideFeedbackTicker) .setTicker(provideFeedbackTicker) .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR, SessionAlarmService.NOTIFICATION_LED_ON_MS, SessionAlarmService.NOTIFICATION_LED_OFF_MS) .setSmallIcon(R.drawable.ic_stat_notification).setPriority(Notification.PRIORITY_LOW) .setLocalOnly(true) // make it local to the phone .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setDeleteIntent(dismissalPendingIntent).setAutoCancel(true); if (needFeedbackIds.size() == 1) { // Only 1 session needs feedback Uri sessionUri = ScheduleContract.Sessions.buildSessionUri(needFeedbackIds.get(0)); PendingIntent pi = TaskStackBuilder.create(this) .addNextIntent(new Intent(this, MyScheduleActivity.class)) .addNextIntent( new Intent(Intent.ACTION_VIEW, sessionUri, this, SessionFeedbackActivity.class)) .getPendingIntent(1, PendingIntent.FLAG_CANCEL_CURRENT); notifBuilder.setContentTitle(needFeedbackTitles.get(0)).setContentIntent(pi); } else { // Show information about several sessions that need feedback PendingIntent pi = TaskStackBuilder.create(this) .addNextIntent(new Intent(this, MyScheduleActivity.class)) .getPendingIntent(1, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(provideFeedbackTicker); for (String title : needFeedbackTitles) { inboxStyle.addLine(title); } notifBuilder .setContentTitle(getResources().getQuantityString(R.plurals.session_plurals, needFeedbackIds.size(), needFeedbackIds.size())) .setStyle(inboxStyle).setContentIntent(pi); } NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); LOGD(TAG, "Now showing session feedback notification!"); nm.notify(FEEDBACK_NOTIFICATION_ID, notifBuilder.build()); /*for (int i = 0; i < needFeedbackIds.size(); i++) { setupNotificationOnWear(needFeedbackIds.get(i), null, needFeedbackTitles.get(i), null); feedbackHelper.setFeedbackNotificationAsFiredForSession(needFeedbackIds.get(i)); }*/ } finally { if (c != null) { try { c.close(); } catch (Exception ignored) { } } } }
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 {// w w w . java 2s .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.google.samples.apps.iosched.service.SessionAlarmService.java
/** * A starred session is about to end. Notify the user to provide session feedback. * Constructs and triggers a system notification. Does nothing if the session has already * concluded./* ww w. j av a 2 s .co m*/ */ private void notifySessionFeedback(boolean debug) { LOGD(TAG, "Considering firing notification for session feedback."); if (debug) { LOGW(TAG, "Note: this is a debug notification."); } // Don't fire notification if this feature is disabled in settings if (!SettingsUtils.shouldShowSessionFeedbackReminders(this)) { LOGD(TAG, "Skipping session feedback notification. Disabled in settings."); return; } Cursor c = null; try { c = getContentResolver().query(ScheduleContract.Sessions.CONTENT_MY_SCHEDULE_URI, SessionsNeedingFeedbackQuery.PROJECTION, SessionsNeedingFeedbackQuery.WHERE_CLAUSE, null, null); if (c == null) { return; } FeedbackHelper feedbackHelper = new FeedbackHelper(this); List<String> needFeedbackIds = new ArrayList<String>(); List<String> needFeedbackTitles = new ArrayList<String>(); while (c.moveToNext()) { String sessionId = c.getString(SessionsNeedingFeedbackQuery.SESSION_ID); String sessionTitle = c.getString(SessionsNeedingFeedbackQuery.SESSION_TITLE); // Avoid repeated notifications. if (feedbackHelper.isFeedbackNotificationFiredForSession(sessionId)) { LOGD(TAG, "Skipping repeated session feedback notification for session '" + sessionTitle + "'"); continue; } needFeedbackIds.add(sessionId); needFeedbackTitles.add(sessionTitle); } if (needFeedbackIds.size() == 0) { // the user has already been notified of all sessions needing feedback return; } LOGD(TAG, "Going forward with session feedback notification for " + needFeedbackIds.size() + " session(s)."); final Resources res = getResources(); // this is used to synchronize deletion of notifications on phone and wear Intent dismissalIntent = new Intent(ACTION_NOTIFICATION_DISMISSAL); // TODO: fix Wear dismiss integration //dismissalIntent.putExtra(KEY_SESSION_ID, sessionId); PendingIntent dismissalPendingIntent = PendingIntent.getService(this, (int) new Date().getTime(), dismissalIntent, PendingIntent.FLAG_UPDATE_CURRENT); String provideFeedbackTicker = res.getString(R.string.session_feedback_notification_ticker); NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this) .setColor(getResources().getColor(R.color.theme_primary)).setContentText(provideFeedbackTicker) .setTicker(provideFeedbackTicker) .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR, SessionAlarmService.NOTIFICATION_LED_ON_MS, SessionAlarmService.NOTIFICATION_LED_OFF_MS) .setSmallIcon(R.drawable.ic_stat_notification).setPriority(Notification.PRIORITY_LOW) .setLocalOnly(true) // make it local to the phone .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setDeleteIntent(dismissalPendingIntent).setAutoCancel(true); if (needFeedbackIds.size() == 1) { // Only 1 session needs feedback Uri sessionUri = ScheduleContract.Sessions.buildSessionUri(needFeedbackIds.get(0)); PendingIntent pi = TaskStackBuilder.create(this) .addNextIntent(new Intent(this, MyScheduleActivity.class)) .addNextIntent( new Intent(Intent.ACTION_VIEW, sessionUri, this, SessionFeedbackActivity.class)) .getPendingIntent(1, PendingIntent.FLAG_CANCEL_CURRENT); notifBuilder.setContentTitle(needFeedbackTitles.get(0)).setContentIntent(pi); } else { // Show information about several sessions that need feedback PendingIntent pi = TaskStackBuilder.create(this) .addNextIntent(new Intent(this, MyScheduleActivity.class)) .getPendingIntent(1, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(provideFeedbackTicker); for (String title : needFeedbackTitles) { inboxStyle.addLine(title); } notifBuilder .setContentTitle(getResources().getQuantityString(R.plurals.session_plurals, needFeedbackIds.size(), needFeedbackIds.size())) .setStyle(inboxStyle).setContentIntent(pi); } NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); LOGD(TAG, "Now showing session feedback notification!"); nm.notify(FEEDBACK_NOTIFICATION_ID, notifBuilder.build()); for (int i = 0; i < needFeedbackIds.size(); i++) { setupNotificationOnWear(needFeedbackIds.get(i), null, needFeedbackTitles.get(i), null); feedbackHelper.setFeedbackNotificationAsFiredForSession(needFeedbackIds.get(i)); } } finally { if (c != null) { try { c.close(); } catch (Exception ignored) { } } } }
From source file:com.nbplus.vbroadlistener.gcm.MyGcmListenerService.java
private void showNotification(Context context, int notificationId, int smallIconId, String title, String contentText, String bigTitle, String bigContentText, String summaryText, String ticker, Intent intent) {/*from w w w . j a v a2 s . co m*/ NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSound(soundUri); if (smallIconId == 0) { builder.setSmallIcon(R.mipmap.ic_launcher); } else { builder.setSmallIcon(smallIconId); } builder.setWhen(System.currentTimeMillis()); //builder.setNumber(10); if (!StringUtils.isEmptyString(ticker)) { builder.setTicker(ticker); } if (StringUtils.isEmptyString(title)) { builder.setContentTitle(PackageUtils.getApplicationName(context)); } else { builder.setContentTitle(title); } builder.setContentText(contentText); builder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE); builder.setAutoCancel(true); // big title and text if (!StringUtils.isEmptyString(bigTitle) && !StringUtils.isEmptyString(bigContentText)) { NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle(builder); if (!StringUtils.isEmptyString(summaryText)) { style.setSummaryText(summaryText); } style.setBigContentTitle(bigTitle); style.bigText(bigContentText); builder.setStyle(style); } if (intent != null) { intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); } notificationManager.notify(notificationId, builder.build()); }
From source file:com.saarang.samples.apps.iosched.service.SessionAlarmService.java
private void notifySessionFeedback(boolean debug) { LogUtils.LOGD(TAG, "Considering firing notification for session feedback."); if (debug) {//from w w w. j a va 2 s. c o m LogUtils.LOGD(TAG, "Note: this is a debug notification."); } // Don't fire notification if this feature is disabled in settings if (!PrefUtils.shouldShowSessionFeedbackReminders(this)) { LogUtils.LOGD(TAG, "Skipping session feedback notification. Disabled in settings."); return; } final Cursor c = getContentResolver().query(ScheduleContract.Sessions.CONTENT_MY_SCHEDULE_URI, SessionsNeedingFeedbackQuery.PROJECTION, SessionsNeedingFeedbackQuery.WHERE_CLAUSE, null, null); if (c == null) { return; } List<String> needFeedbackIds = new ArrayList<String>(); List<String> needFeedbackTitles = new ArrayList<String>(); while (c.moveToNext()) { String sessionId = c.getString(SessionsNeedingFeedbackQuery.SESSION_ID); String sessionTitle = c.getString(SessionsNeedingFeedbackQuery.SESSION_TITLE); // Avoid repeated notifications. if (UIUtils.isFeedbackNotificationFiredForSession(this, sessionId)) { LogUtils.LOGD(TAG, "Skipping repeated session feedback notification for session '" + sessionTitle + "'"); continue; } needFeedbackIds.add(sessionId); needFeedbackTitles.add(sessionTitle); } if (needFeedbackIds.size() == 0) { // the user has already been notified of all sessions needing feedback return; } LogUtils.LOGD(TAG, "Going forward with session feedback notification for " + needFeedbackIds.size() + " session(s)."); final Resources res = getResources(); // this is used to synchronize deletion of notifications on phone and wear Intent dismissalIntent = new Intent(ACTION_NOTIFICATION_DISMISSAL); // TODO: fix Wear dismiss integration //dismissalIntent.putExtra(KEY_SESSION_ID, sessionId); PendingIntent dismissalPendingIntent = PendingIntent.getService(this, (int) new Date().getTime(), dismissalIntent, PendingIntent.FLAG_UPDATE_CURRENT); String provideFeedbackTicker = res .getString(com.saarang.samples.apps.iosched.R.string.session_feedback_notification_ticker); NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this) .setColor(getResources().getColor(com.saarang.samples.apps.iosched.R.color.theme_primary)) .setContentText(provideFeedbackTicker).setTicker(provideFeedbackTicker) .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR, SessionAlarmService.NOTIFICATION_LED_ON_MS, SessionAlarmService.NOTIFICATION_LED_OFF_MS) .setSmallIcon(com.saarang.samples.apps.iosched.R.drawable.ic_stat_notification) .setPriority(Notification.PRIORITY_LOW).setLocalOnly(true) // make it local to the phone .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setDeleteIntent(dismissalPendingIntent).setAutoCancel(true); if (needFeedbackIds.size() == 1) { // Only 1 session needs feedback Uri sessionUri = ScheduleContract.Sessions.buildSessionUri(needFeedbackIds.get(0)); PendingIntent pi = TaskStackBuilder.create(this) .addNextIntent(new Intent(this, MyScheduleActivity.class)) .addNextIntent(new Intent(Intent.ACTION_VIEW, sessionUri, this, SessionFeedbackActivity.class)) .getPendingIntent(1, PendingIntent.FLAG_CANCEL_CURRENT); notifBuilder.setContentTitle(needFeedbackTitles.get(0)).setContentIntent(pi); } else { // Show information about several sessions that need feedback PendingIntent pi = TaskStackBuilder.create(this) .addNextIntent(new Intent(this, MyScheduleActivity.class)) .getPendingIntent(1, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(provideFeedbackTicker); for (String title : needFeedbackTitles) { inboxStyle.addLine(title); } notifBuilder.setContentTitle( getResources().getQuantityString(com.saarang.samples.apps.iosched.R.plurals.session_plurals, needFeedbackIds.size(), needFeedbackIds.size())) .setStyle(inboxStyle).setContentIntent(pi); } NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); LogUtils.LOGD(TAG, "Now showing session feedback notification!"); nm.notify(FEEDBACK_NOTIFICATION_ID, notifBuilder.build()); for (int i = 0; i < needFeedbackIds.size(); i++) { setupNotificationOnWear(needFeedbackIds.get(i), null, needFeedbackTitles.get(i), null); } }
From source file:com.razza.apps.iosched.service.SessionAlarmService.java
/** * A starred session is about to end. Notify the user to provide session feedback. * Constructs and triggers a system notification. Does nothing if the session has already * concluded.//w w w .ja va 2 s. com */ private void notifySessionFeedback(boolean debug) { LogUtils.LOGD(TAG, "Considering firing notification for session feedback."); if (debug) { LogUtils.LOGW(TAG, "Note: this is a debug notification."); } // Don't fire notification if this feature is disabled in settings if (!SettingsUtils.shouldShowSessionFeedbackReminders(this)) { LogUtils.LOGD(TAG, "Skipping session feedback notification. Disabled in settings."); return; } Cursor c = null; try { c = getContentResolver().query(ScheduleContract.Sessions.CONTENT_MY_SCHEDULE_URI, SessionsNeedingFeedbackQuery.PROJECTION, SessionsNeedingFeedbackQuery.WHERE_CLAUSE, null, null); if (c == null) { return; } FeedbackHelper feedbackHelper = new FeedbackHelper(this); List<String> needFeedbackIds = new ArrayList<String>(); List<String> needFeedbackTitles = new ArrayList<String>(); while (c.moveToNext()) { String sessionId = c.getString(SessionsNeedingFeedbackQuery.SESSION_ID); String sessionTitle = c.getString(SessionsNeedingFeedbackQuery.SESSION_TITLE); // Avoid repeated notifications. if (feedbackHelper.isFeedbackNotificationFiredForSession(sessionId)) { LogUtils.LOGD(TAG, "Skipping repeated session feedback notification for session '" + sessionTitle + "'"); continue; } needFeedbackIds.add(sessionId); needFeedbackTitles.add(sessionTitle); } if (needFeedbackIds.size() == 0) { // the user has already been notified of all sessions needing feedback return; } LogUtils.LOGD(TAG, "Going forward with session feedback notification for " + needFeedbackIds.size() + " session(s)."); final Resources res = getResources(); // this is used to synchronize deletion of notifications on phone and wear Intent dismissalIntent = new Intent(ACTION_NOTIFICATION_DISMISSAL); // TODO: fix Wear dismiss integration //dismissalIntent.putExtra(KEY_SESSION_ID, sessionId); PendingIntent dismissalPendingIntent = PendingIntent.getService(this, (int) new Date().getTime(), dismissalIntent, PendingIntent.FLAG_UPDATE_CURRENT); String provideFeedbackTicker = res.getString(R.string.session_feedback_notification_ticker); NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this) .setColor(getResources().getColor(R.color.theme_primary)).setContentText(provideFeedbackTicker) .setTicker(provideFeedbackTicker) .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR, SessionAlarmService.NOTIFICATION_LED_ON_MS, SessionAlarmService.NOTIFICATION_LED_OFF_MS) .setSmallIcon(R.drawable.ic_stat_notification).setPriority(Notification.PRIORITY_LOW) .setLocalOnly(true) // make it local to the phone .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setDeleteIntent(dismissalPendingIntent).setAutoCancel(true); if (needFeedbackIds.size() == 1) { // Only 1 session needs feedback Uri sessionUri = ScheduleContract.Sessions.buildSessionUri(needFeedbackIds.get(0)); PendingIntent pi = TaskStackBuilder.create(this) .addNextIntent(new Intent(this, MyScheduleActivity.class)) .addNextIntent( new Intent(Intent.ACTION_VIEW, sessionUri, this, SessionFeedbackActivity.class)) .getPendingIntent(1, PendingIntent.FLAG_CANCEL_CURRENT); notifBuilder.setContentTitle(needFeedbackTitles.get(0)).setContentIntent(pi); } else { // Show information about several sessions that need feedback PendingIntent pi = TaskStackBuilder.create(this) .addNextIntent(new Intent(this, MyScheduleActivity.class)) .getPendingIntent(1, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(provideFeedbackTicker); for (String title : needFeedbackTitles) { inboxStyle.addLine(title); } notifBuilder .setContentTitle(getResources().getQuantityString(R.plurals.session_plurals, needFeedbackIds.size(), needFeedbackIds.size())) .setStyle(inboxStyle).setContentIntent(pi); } NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); LogUtils.LOGD(TAG, "Now showing session feedback notification!"); nm.notify(FEEDBACK_NOTIFICATION_ID, notifBuilder.build()); for (int i = 0; i < needFeedbackIds.size(); i++) { setupNotificationOnWear(needFeedbackIds.get(i), null, needFeedbackTitles.get(i), null); feedbackHelper.setFeedbackNotificationAsFiredForSession(needFeedbackIds.get(i)); } } finally { if (c != null) { try { c.close(); } catch (Exception ignored) { } } } }
From source file:org.linphone.compatibility.ApiFivePlus.java
public static Notification createSimpleNotification(Context context, String title, String text, PendingIntent intent) {/* ww w . java2s.c om*/ NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.logo_linphone_57x57).setContentTitle(title).setContentText(text) .setContentIntent(intent); Notification notif = notifBuilder.build(); notif.defaults |= Notification.DEFAULT_VIBRATE; notif.defaults |= Notification.DEFAULT_SOUND; notif.defaults |= Notification.DEFAULT_LIGHTS; return notif; }
From source file:at.jclehner.rxdroid.NotificationReceiver.java
public void updateNotification(Date date, int doseTime, boolean isActiveDoseTime, int mode) { final List<Drug> drugsWithLowSupplies = new ArrayList<Drug>(); final int lowSupplyDrugCount = getDrugsWithLowSupplies(date, doseTime, drugsWithLowSupplies); final int missedDoseCount = getDrugsWithMissedDoses(date, doseTime, isActiveDoseTime, null); final int dueDoseCount = isActiveDoseTime ? getDrugsWithDueDoses(date, doseTime, null) : 0; int titleResId = R.string._title_notification_doses; int icon = R.drawable.ic_stat_normal; final StringBuilder sb = new StringBuilder(); final String[] lines = new String[2]; int lineCount = 0; if (missedDoseCount != 0 || dueDoseCount != 0) { if (dueDoseCount != 0) sb.append(RxDroid.getQuantityString(R.plurals._qmsg_due, dueDoseCount)); if (missedDoseCount != 0) { if (sb.length() != 0) sb.append(", "); sb.append(RxDroid.getQuantityString(R.plurals._qmsg_missed, missedDoseCount)); }/*from w w w. j a v a2 s . c o m*/ lines[1] = "<b>" + getString(R.string._title_notification_doses) + "</b> " + Util.escapeHtml(sb.toString()); } final boolean isShowingLowSupplyNotification; if (lowSupplyDrugCount != 0) { final String msg; final String first = drugsWithLowSupplies.get(0).getName(); icon = R.drawable.ic_stat_exclamation; isShowingLowSupplyNotification = sb.length() == 0; //titleResId = R.string._title_notification_low_supplies; if (lowSupplyDrugCount == 1) msg = getString(R.string._qmsg_low_supply_single, first); else { final String second = drugsWithLowSupplies.get(1).getName(); msg = RxDroid.getQuantityString(R.plurals._qmsg_low_supply_multiple, lowSupplyDrugCount - 1, first, second); } if (isShowingLowSupplyNotification) { sb.append(msg); titleResId = R.string._title_notification_low_supplies; } lines[0] = "<b>" + getString(R.string._title_notification_low_supplies) + "</b> " + Util.escapeHtml(msg); } else isShowingLowSupplyNotification = false; final int priority; if (isShowingLowSupplyNotification) priority = NotificationCompat.PRIORITY_DEFAULT; else priority = NotificationCompat.PRIORITY_HIGH; final String message = sb.toString(); final int currentHash = message.hashCode(); final int lastHash = Settings.getInt(Settings.Keys.LAST_MSG_HASH); if (message.length() == 0) { getNotificationManager().cancel(R.id.notification); return; } final StringBuilder source = new StringBuilder(); // final InboxStyle inboxStyle = new InboxStyle(); // inboxStyle.setBigContentTitle(getString(R.string.app_name) + // " (" + (dueDoseCount + missedDoseCount + lowSupplyDrugCount) + ")"); for (String line : lines) { if (line != null) { if (lineCount != 0) source.append("\n<br/>\n"); source.append(line); // inboxStyle.addLine(Html.fromHtml(line)); ++lineCount; } } final NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext); builder.setContentTitle(getString(titleResId)); builder.setContentIntent(createDrugListIntent(date)); builder.setContentText(message); builder.setTicker(getString(R.string._msg_new_notification)); builder.setSmallIcon(icon); builder.setOngoing(true); builder.setUsesChronometer(false); builder.setWhen(0); builder.setPriority(priority); if (lineCount > 1) { final BigTextStyle style = new BigTextStyle(); style.setBigContentTitle(getString(R.string.app_name)); style.bigText(Html.fromHtml(source.toString())); builder.setStyle(style); } // final long offset; // // if(isActiveDoseTime) // offset = Settings.getDoseTimeBeginOffset(doseTime); // else // offset = Settings.getTrueDoseTimeEndOffset(doseTime); // // builder.setWhen(date.getTime() + offset); if (mode == NOTIFICATION_FORCE_UPDATE || currentHash != lastHash) { builder.setOnlyAlertOnce(false); Settings.putInt(Settings.Keys.LAST_MSG_HASH, currentHash); } else builder.setOnlyAlertOnce(true); // Prevents low supplies from constantly annoying the user with // notification's sound and/or vibration if alarms are repeated. if (isShowingLowSupplyNotification) mode = NOTIFICATION_FORCE_SILENT; int defaults = 0; final String lightColor = Settings.getString(Settings.Keys.NOTIFICATION_LIGHT_COLOR, ""); if (lightColor.length() == 0) defaults |= Notification.DEFAULT_LIGHTS; else { try { int ledARGB = Integer.parseInt(lightColor, 16); if (ledARGB != 0) { ledARGB |= 0xff000000; // set alpha to ff builder.setLights(ledARGB, LED_ON_MS, LED_OFF_MS); } } catch (NumberFormatException e) { Log.e(TAG, "Failed to parse light color; using default", e); defaults |= Notification.DEFAULT_LIGHTS; } } if (mode != NOTIFICATION_FORCE_SILENT) { boolean isNowWithinQuietHours = false; do { if (!Settings.isChecked(Settings.Keys.QUIET_HOURS, false)) break; final String quietHoursStr = Settings.getString(Settings.Keys.QUIET_HOURS); if (quietHoursStr == null) break; final TimePeriod quietHours = TimePeriod.fromString(quietHoursStr); if (quietHours.contains(DumbTime.now())) isNowWithinQuietHours = true; } while (false); if (!isNowWithinQuietHours) { final String ringtone = Settings.getString(Settings.Keys.NOTIFICATION_SOUND); if (ringtone != null) builder.setSound(Uri.parse(ringtone)); else defaults |= Notification.DEFAULT_SOUND; if (LOGV) Log.i(TAG, "Sound: " + (ringtone != null ? ringtone.toString() : "(default)")); } else Log.i(TAG, "Currently within quiet hours; muting sound..."); } if (mode != NOTIFICATION_FORCE_SILENT && Settings.getBoolean(Settings.Keys.USE_VIBRATOR, true)) defaults |= Notification.DEFAULT_VIBRATE; builder.setDefaults(defaults); getNotificationManager().notify(R.id.notification, builder.build()); }
From source file:im.neon.util.NotificationUtils.java
/** * Build a message notification./*from w ww . j a v a 2 s .com*/ * @param context the context * @param from the sender * @param matrixId the user account id; * @param displayMatrixId true to display the matrix id * @param largeIcon the notification icon * @param unseenNotifiedRoomsCount the number of notified rooms * @param body the message body * @param roomId the room id * @param roomName the room name * @param shouldPlaySound true when the notification as sound. * @param isInvitationEvent true if it is an invitation notification * @return the notification */ public static Notification buildMessageNotification(Context context, String from, String matrixId, boolean displayMatrixId, Bitmap largeIcon, int unseenNotifiedRoomsCount, String body, String roomId, String roomName, boolean shouldPlaySound, boolean isInvitationEvent) { NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setWhen(System.currentTimeMillis()); if (!TextUtils.isEmpty(from)) { // don't display the room name for 1:1 room notifications. if (!TextUtils.isEmpty(roomName) && !roomName.equals(from)) { builder.setContentTitle(from + " (" + roomName + ")"); } else { builder.setContentTitle(from); } } else { builder.setContentTitle(roomName); } builder.setContentText(body); builder.setAutoCancel(true); builder.setSmallIcon(R.drawable.message_notification_transparent); if (null != largeIcon) { largeIcon = createSquareBitmap(largeIcon); // add a bubble in the top right if (0 != unseenNotifiedRoomsCount) { try { android.graphics.Bitmap.Config bitmapConfig = largeIcon.getConfig(); // set default bitmap config if none if (bitmapConfig == null) { bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888; } // setLargeIcon must used a 64 * 64 pixels bitmap // rescale to have the same text UI. float densityScale = context.getResources().getDisplayMetrics().density; int side = (int) (64 * densityScale); Bitmap bitmapCopy = Bitmap.createBitmap(side, side, bitmapConfig); Canvas canvas = new Canvas(bitmapCopy); // resize the bitmap to fill in size int bitmapWidth = largeIcon.getWidth(); int bitmapHeight = largeIcon.getHeight(); float scale = Math.min((float) canvas.getWidth() / (float) bitmapWidth, (float) canvas.getHeight() / (float) bitmapHeight); int scaledWidth = (int) (bitmapWidth * scale); int scaledHeight = (int) (bitmapHeight * scale); Bitmap rescaledBitmap = Bitmap.createScaledBitmap(largeIcon, scaledWidth, scaledHeight, true); canvas.drawBitmap(rescaledBitmap, (side - scaledWidth) / 2, (side - scaledHeight) / 2, null); String text = "" + unseenNotifiedRoomsCount; // prepare the text drawing Paint textPaint = new Paint(); textPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD)); textPaint.setColor(Color.WHITE); textPaint.setTextSize(10 * densityScale); // get its size Rect textBounds = new Rect(); if (-1 == mUnreadBubbleWidth) { textPaint.getTextBounds("99", 0, 2, textBounds); mUnreadBubbleWidth = textBounds.width(); } textPaint.getTextBounds(text, 0, text.length(), textBounds); // draw a red circle int radius = mUnreadBubbleWidth; Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.RED); canvas.drawCircle(canvas.getWidth() - radius, radius, radius, paint); // draw the text canvas.drawText(text, canvas.getWidth() - textBounds.width() - (radius - (textBounds.width() / 2)), -textBounds.top + (radius - (-textBounds.top / 2)), textPaint); // get the new bitmap largeIcon = bitmapCopy; } catch (Exception e) { Log.e(LOG_TAG, "## buildMessageNotification(): Exception Msg=" + e.getMessage()); } } builder.setLargeIcon(largeIcon); } String name = ": "; if (!TextUtils.isEmpty(roomName)) { name = " (" + roomName + "): "; } if (displayMatrixId) { from = "[" + matrixId + "]\n" + from; } builder.setTicker(from + name + body); TaskStackBuilder stackBuilder; Intent intent; intent = new Intent(context, VectorRoomActivity.class); intent.putExtra(VectorRoomActivity.EXTRA_ROOM_ID, roomId); if (null != matrixId) { intent.putExtra(VectorRoomActivity.EXTRA_MATRIX_ID, matrixId); } stackBuilder = TaskStackBuilder.create(context).addParentStack(VectorRoomActivity.class) .addNextIntent(intent); // android 4.3 issue // use a generator for the private requestCode. // When using 0, the intent is not created/launched when the user taps on the notification. // PendingIntent pendingIntent = stackBuilder.getPendingIntent((new Random()).nextInt(1000), PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); // display the message with more than 1 lines when the device supports it NotificationCompat.BigTextStyle textStyle = new NotificationCompat.BigTextStyle(); textStyle.bigText(from + ":" + body); builder.setStyle(textStyle); // do not offer to quick respond if the user did not dismiss the previous one if (!LockScreenActivity.isDisplayingALockScreenActivity()) { if (!isInvitationEvent) { // offer to type a quick answer (i.e. without launching the application) Intent quickReplyIntent = new Intent(context, LockScreenActivity.class); quickReplyIntent.putExtra(LockScreenActivity.EXTRA_ROOM_ID, roomId); quickReplyIntent.putExtra(LockScreenActivity.EXTRA_SENDER_NAME, from); quickReplyIntent.putExtra(LockScreenActivity.EXTRA_MESSAGE_BODY, body); if (null != matrixId) { quickReplyIntent.putExtra(LockScreenActivity.EXTRA_MATRIX_ID, matrixId); } // the action must be unique else the parameters are ignored quickReplyIntent.setAction(QUICK_LAUNCH_ACTION + ((int) (System.currentTimeMillis()))); PendingIntent pIntent = PendingIntent.getActivity(context, 0, quickReplyIntent, 0); builder.addAction(R.drawable.vector_notification_quick_reply, context.getString(R.string.action_quick_reply), pIntent); } else { { // offer to type a quick reject button Intent leaveIntent = new Intent(context, JoinScreenActivity.class); leaveIntent.putExtra(JoinScreenActivity.EXTRA_ROOM_ID, roomId); leaveIntent.putExtra(JoinScreenActivity.EXTRA_MATRIX_ID, matrixId); leaveIntent.putExtra(JoinScreenActivity.EXTRA_REJECT, true); // the action must be unique else the parameters are ignored leaveIntent.setAction(QUICK_LAUNCH_ACTION + ((int) (System.currentTimeMillis()))); PendingIntent pIntent = PendingIntent.getActivity(context, 0, leaveIntent, 0); builder.addAction(R.drawable.vector_notification_reject_invitation, context.getString(R.string.reject), pIntent); } { // offer to type a quick accept button Intent acceptIntent = new Intent(context, JoinScreenActivity.class); acceptIntent.putExtra(JoinScreenActivity.EXTRA_ROOM_ID, roomId); acceptIntent.putExtra(JoinScreenActivity.EXTRA_MATRIX_ID, matrixId); acceptIntent.putExtra(JoinScreenActivity.EXTRA_JOIN, true); // the action must be unique else the parameters are ignored acceptIntent.setAction(QUICK_LAUNCH_ACTION + ((int) (System.currentTimeMillis()))); PendingIntent pIntent = PendingIntent.getActivity(context, 0, acceptIntent, 0); builder.addAction(R.drawable.vector_notification_accept_invitation, context.getString(R.string.join), pIntent); } } // Build the pending intent for when the notification is clicked Intent roomIntentTap; if (isInvitationEvent) { // for invitation the room preview must be displayed roomIntentTap = CommonActivityUtils.buildIntentPreviewRoom(matrixId, roomId, context, VectorFakeRoomPreviewActivity.class); } else { roomIntentTap = new Intent(context, VectorRoomActivity.class); roomIntentTap.putExtra(VectorRoomActivity.EXTRA_ROOM_ID, roomId); } // the action must be unique else the parameters are ignored roomIntentTap.setAction(TAP_TO_VIEW_ACTION + ((int) (System.currentTimeMillis()))); // Recreate the back stack TaskStackBuilder stackBuilderTap = TaskStackBuilder.create(context) .addParentStack(VectorRoomActivity.class).addNextIntent(roomIntentTap); builder.addAction(R.drawable.vector_notification_open, context.getString(R.string.action_open), stackBuilderTap.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)); } //extendForCar(context, builder, roomId, roomName, from, body); Notification n = builder.build(); n.flags |= Notification.FLAG_SHOW_LIGHTS; n.defaults |= Notification.DEFAULT_LIGHTS; if (shouldPlaySound) { n.defaults |= Notification.DEFAULT_SOUND; } if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { // some devices crash if this field is not set // even if it is deprecated // setLatestEventInfo() is deprecated on Android M, so we try to use // reflection at runtime, to avoid compiler error: "Cannot resolve method.." try { Method deprecatedMethod = n.getClass().getMethod("setLatestEventInfo", Context.class, CharSequence.class, CharSequence.class, PendingIntent.class); deprecatedMethod.invoke(n, context, from, body, pendingIntent); } catch (Exception ex) { Log.e(LOG_TAG, "## buildMessageNotification(): Exception - setLatestEventInfo() Msg=" + ex.getMessage()); } } return n; }