List of usage examples for android.app PendingIntent FLAG_CANCEL_CURRENT
int FLAG_CANCEL_CURRENT
To view the source code for android.app PendingIntent FLAG_CANCEL_CURRENT.
Click Source Link
From source file:com.voiceblue.phone.service.SipNotifications.java
public void showNotificationForMessage(SipMessage msg) { if (!CustomDistribution.supportMessaging()) { return;//w ww . ja va 2 s. c o m } // CharSequence tickerText = context.getText(R.string.instance_message); if (!msg.getFrom().equalsIgnoreCase(viewingRemoteFrom)) { String from = formatRemoteContactString(msg.getFullFrom()); if (from.equalsIgnoreCase(msg.getFullFrom()) && !from.equals(msg.getDisplayName())) { from = msg.getDisplayName() + " " + from; } CharSequence tickerText = buildTickerMessage(context, from, msg.getBody()); if (messageNotification == null) { messageNotification = new NotificationCompat.Builder(context); messageNotification.setSmallIcon(SipUri.isPhoneNumber(from) ? R.drawable.stat_notify_sms : android.R.drawable.stat_notify_chat); messageNotification.setTicker(tickerText); messageNotification.setWhen(System.currentTimeMillis()); messageNotification.setDefaults(Notification.DEFAULT_ALL); messageNotification.setAutoCancel(true); messageNotification.setOnlyAlertOnce(true); } Intent notificationIntent = new Intent(SipManager.ACTION_SIP_MESSAGES); notificationIntent.putExtra(SipMessage.FIELD_FROM, msg.getFrom()); notificationIntent.putExtra(SipMessage.FIELD_BODY, msg.getBody()); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); messageNotification.setContentTitle(from); messageNotification.setContentText(msg.getBody()); messageNotification.setContentIntent(contentIntent); notificationManager.notify(MESSAGE_NOTIF_ID, messageNotification.build()); } }
From source file:com.morlunk.mumbleclient.service.PlumbleService.java
/** * Creates a new NotificationCompat.Builder configured for the service, and shows it. *///from ww w. java2 s .co m public void createNotification() { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.ic_stat_notify); builder.setTicker(getResources().getString(R.string.plumbleConnected)); builder.setContentTitle(getResources().getString(R.string.app_name)); builder.setContentText(getResources().getString(R.string.connected)); builder.setPriority(NotificationCompat.PRIORITY_HIGH); builder.setOngoing(true); // Add notification triggers Intent muteIntent = new Intent(BROADCAST_MUTE); Intent deafenIntent = new Intent(BROADCAST_DEAFEN); Intent overlayIntent = new Intent(BROADCAST_TOGGLE_OVERLAY); if (isConnected()) { builder.addAction(R.drawable.ic_action_microphone, getString(R.string.mute), PendingIntent.getBroadcast(this, 1, muteIntent, PendingIntent.FLAG_CANCEL_CURRENT)); builder.addAction(R.drawable.ic_action_audio, getString(R.string.deafen), PendingIntent.getBroadcast(this, 1, deafenIntent, PendingIntent.FLAG_CANCEL_CURRENT)); builder.addAction(R.drawable.ic_action_channels, getString(R.string.overlay), PendingIntent.getBroadcast(this, 2, overlayIntent, PendingIntent.FLAG_CANCEL_CURRENT)); } Intent channelListIntent = new Intent(this, PlumbleActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, channelListIntent, 0); builder.setContentIntent(pendingIntent); mStatusNotificationBuilder = builder; startForeground(STATUS_NOTIFICATION_ID, builder.build()); }
From source file:com.battlelancer.seriesguide.service.NotificationService.java
private void onNotify(final Cursor upcomingEpisodes, List<Integer> notifyPositions, long latestAirtime) { final Context context = getApplicationContext(); CharSequence tickerText;// ww w . jav a 2 s. c o m CharSequence contentTitle; CharSequence contentText; PendingIntent contentIntent; // base intent for task stack final Intent showsIntent = new Intent(context, ShowsActivity.class); showsIntent.putExtra(ShowsActivity.InitBundle.SELECTED_TAB, ShowsActivity.InitBundle.INDEX_TAB_UPCOMING); final int count = notifyPositions.size(); if (count == 1) { // notify in detail about one episode Timber.d("Notifying about 1 new episode"); upcomingEpisodes.moveToPosition(notifyPositions.get(0)); final String showTitle = upcomingEpisodes.getString(NotificationQuery.SHOW_TITLE); tickerText = getString(R.string.upcoming_show, showTitle); contentTitle = showTitle + " " + Utils.getEpisodeNumber(this, upcomingEpisodes.getInt(NotificationQuery.SEASON), upcomingEpisodes.getInt(NotificationQuery.NUMBER)); // "8:00 PM on Network" final String releaseTime = TimeTools.formatToLocalReleaseTime(this, TimeTools.getEpisodeReleaseTime( this, upcomingEpisodes.getLong(NotificationQuery.EPISODE_FIRST_RELEASE_MS))); final String network = upcomingEpisodes.getString(NotificationQuery.NETWORK); contentText = getString(R.string.upcoming_show_detailed, releaseTime, network); Intent episodeDetailsIntent = new Intent(context, EpisodesActivity.class); episodeDetailsIntent.putExtra(EpisodesActivity.InitBundle.EPISODE_TVDBID, upcomingEpisodes.getInt(NotificationQuery._ID)); episodeDetailsIntent.putExtra(KEY_EPISODE_CLEARED_TIME, latestAirtime); contentIntent = TaskStackBuilder.create(context).addNextIntent(showsIntent) .addNextIntent(episodeDetailsIntent) .getPendingIntent(REQUEST_CODE_SINGLE_EPISODE, PendingIntent.FLAG_CANCEL_CURRENT); } else { // notify about multiple episodes Timber.d("Notifying about " + count + " new episodes"); tickerText = getString(R.string.upcoming_episodes); contentTitle = getString(R.string.upcoming_episodes_number, count); contentText = getString(R.string.upcoming_display); contentIntent = TaskStackBuilder.create(context) .addNextIntent(showsIntent.putExtra(KEY_EPISODE_CLEARED_TIME, latestAirtime)) .getPendingIntent(REQUEST_CODE_MULTIPLE_EPISODES, PendingIntent.FLAG_CANCEL_CURRENT); } final NotificationCompat.Builder nb = new NotificationCompat.Builder(context); if (AndroidUtils.isJellyBeanOrHigher()) { Timber.d("Building rich notification (JB+)"); // JELLY BEAN and above if (count == 1) { // single episode upcomingEpisodes.moveToPosition(notifyPositions.get(0)); maybeSetPoster(context, nb, upcomingEpisodes.getString(NotificationQuery.POSTER)); final String episodeTitle = upcomingEpisodes.getString(NotificationQuery.TITLE); final String episodeSummary = upcomingEpisodes.getString(NotificationQuery.OVERVIEW); final SpannableStringBuilder bigText = new SpannableStringBuilder(); bigText.append(TextUtils.isEmpty(episodeTitle) ? "" : episodeTitle); bigText.setSpan(new StyleSpan(Typeface.BOLD), 0, bigText.length(), 0); bigText.append("\n"); bigText.append(TextUtils.isEmpty(episodeSummary) ? "" : episodeSummary); nb.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText).setSummaryText(contentText)); // Action button to check in Intent checkInActionIntent = new Intent(context, QuickCheckInActivity.class); checkInActionIntent.putExtra(QuickCheckInActivity.InitBundle.EPISODE_TVDBID, upcomingEpisodes.getInt(NotificationQuery._ID)); checkInActionIntent .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); PendingIntent checkInIntent = PendingIntent.getActivity(context, REQUEST_CODE_ACTION_CHECKIN, checkInActionIntent, PendingIntent.FLAG_CANCEL_CURRENT); nb.addAction(R.drawable.ic_action_checkin, getString(R.string.checkin), checkInIntent); } else { // multiple episodes NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); // display at most the first five for (int displayIndex = 0; displayIndex < Math.min(count, 5); displayIndex++) { if (!upcomingEpisodes.moveToPosition(notifyPositions.get(displayIndex))) { // could not go to the desired position (testing just in case) break; } final SpannableStringBuilder lineText = new SpannableStringBuilder(); // show title String showTitle = upcomingEpisodes.getString(NotificationQuery.SHOW_TITLE); lineText.append(TextUtils.isEmpty(showTitle) ? "" : showTitle); lineText.setSpan(new StyleSpan(Typeface.BOLD), 0, lineText.length(), 0); lineText.append(" "); // "8:00 PM on Network" String releaseTime = TimeTools.formatToLocalReleaseTime(this, TimeTools.getEpisodeReleaseTime( this, upcomingEpisodes.getLong(NotificationQuery.EPISODE_FIRST_RELEASE_MS))); String network = upcomingEpisodes.getString(NotificationQuery.NETWORK); lineText.append(getString(R.string.upcoming_show_detailed, releaseTime, network)); inboxStyle.addLine(lineText); } // tell if we could not display all episodes if (count > 5) { inboxStyle.setSummaryText(getString(R.string.more, count - 5)); } nb.setStyle(inboxStyle); nb.setContentInfo(String.valueOf(count)); } } else { // ICS and below if (count == 1) { // single episode upcomingEpisodes.moveToPosition(notifyPositions.get(0)); maybeSetPoster(context, nb, upcomingEpisodes.getString(NotificationQuery.POSTER)); } } // notification sound final String ringtoneUri = NotificationSettings.getNotificationsRingtone(context); // If the string is empty, the user chose silent... if (ringtoneUri.length() != 0) { // ...otherwise set the specified ringtone Timber.d("Notification has sound"); nb.setSound(Uri.parse(ringtoneUri)); } // vibration if (NotificationSettings.isNotificationVibrating(context)) { Timber.d("Notification vibrates"); nb.setVibrate(VIBRATION_PATTERN); } nb.setDefaults(Notification.DEFAULT_LIGHTS); nb.setWhen(System.currentTimeMillis()); nb.setAutoCancel(true); nb.setTicker(tickerText); nb.setContentTitle(contentTitle); nb.setContentText(contentText); nb.setContentIntent(contentIntent); nb.setSmallIcon(R.drawable.ic_notification); nb.setColor(getResources().getColor(R.color.accent_primary)); nb.setPriority(NotificationCompat.PRIORITY_DEFAULT); nb.setCategory(NotificationCompat.CATEGORY_EVENT); Timber.d("Setting delete intent with episode time: " + latestAirtime); Intent i = new Intent(this, NotificationService.class); i.putExtra(KEY_EPISODE_CLEARED_TIME, latestAirtime); PendingIntent deleteIntent = PendingIntent.getService(this, REQUEST_CODE_DELETE_INTENT, i, PendingIntent.FLAG_CANCEL_CURRENT); nb.setDeleteIntent(deleteIntent); // build the notification Notification notification = nb.build(); // use string resource id, always unique within app final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(R.string.upcoming_show, notification); }
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 av a 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.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./* www. ja v a2 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.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.//from www . j a v a2 s. c o m */ 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:com.sonetel.service.SipNotifications.java
public void showNotificationForCall(SipCallSession callInfo) { // This is the pending call notification // int icon = R.drawable.ic_incall_ongoing; @SuppressWarnings("deprecation") int icon = android.R.drawable.stat_sys_phone_call; CharSequence tickerText = context.getText(R.string.ongoing_call); long when = System.currentTimeMillis(); if (inCallNotification == null) { inCallNotification = new NotificationCompat.Builder(context); inCallNotification.setSmallIcon(icon); inCallNotification.setTicker(tickerText); inCallNotification.setWhen(when); inCallNotification.setOngoing(true); }// www . j ava2 s.c o m Intent notificationIntent = SipService.buildCallUiIntent(context, callInfo); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); inCallNotification.setContentTitle(formatNotificationTitle(R.string.ongoing_call, callInfo.getAccId())); inCallNotification.setContentText(formatRemoteContactString(callInfo.getRemoteContact())); inCallNotification.setContentIntent(contentIntent); Notification notification = inCallNotification.getNotification(); notification.flags |= Notification.FLAG_NO_CLEAR; notificationManager.notify(CALL_NOTIF_ID, notification); }
From source file:org.restcomm.app.qoslib.Services.TrackingManager.java
/** * Cancels all scheduled tracking events. * Does not stop a currently running tracking event. *//* w w w .j a v a 2s . co m*/ public void cancelScheduledEvents() { //if(timer != null) { // timer.cancel(); // timer = null; //} try { LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, TAG, "cancelScheduledEvents", ""); bTracking = false; if (prevTrackingTime > 0) { trackingElapsed += (System.currentTimeMillis() - prevTrackingTime + 500) / 1000; PreferenceManager.getDefaultSharedPreferences(owner).edit() .putInt(PreferenceKeys.Miscellaneous.TRACKING_ELAPSED, trackingElapsed).commit(); if (durMinutes > 0 && trackingElapsed >= (durMinutes - 1) * 60) { testTrigger = ""; } } prevTrackingTime = System.currentTimeMillis(); if (testTrigger.equals("")) trackingElapsed = 1000000; //trackingExpires = System.currentTimeMillis() - 10000; PreferenceManager.getDefaultSharedPreferences(owner).edit() .putInt(PreferenceKeys.Miscellaneous.TRACKING_ELAPSED, trackingElapsed).commit(); PreferenceManager.getDefaultSharedPreferences(owner).edit() .putLong(PreferenceKeys.Miscellaneous.ENGINEER_MODE_EXPIRES_TIME, 0L).commit(); AlarmManager alarmMgr = (AlarmManager) owner.getSystemService(Service.ALARM_SERVICE); Intent intent = new Intent(IntentHandler.ACTION_TRACKING_5MINUTE); PendingIntent alarm = PendingIntent.getBroadcast(owner, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); alarmMgr.cancel(alarm); handler.removeCallbacks(testRunnable); } catch (Exception e) { LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, TAG, "cancelScheduledEvents", "Exception", e); } }
From source file:org.ohmage.reminders.types.location.LocTrigService.java
private void setTriggerAlwaysAlarm(int trigId, String trigDesc) { cancelTriggerAlwaysAlarm(trigId);// w w w.ja v a2s . c o m LocTrigDesc desc = new LocTrigDesc(); if (!desc.loadString(trigDesc)) { return; } if (!desc.shouldTriggerAlways()) { return; } Log.v(TAG, "LocTrigService: Setting trigger always alarm(" + trigId + ", " + trigDesc + ")"); Calendar target = Calendar.getInstance(); target.set(Calendar.HOUR_OF_DAY, desc.getEndTime().getHour()); target.set(Calendar.MINUTE, desc.getEndTime().getMinute()); target.set(Calendar.SECOND, 0); LocationTrigger locTrig = new LocationTrigger(); if (locTrig.hasTriggeredToday(this, trigId)) { target.add(Calendar.DAY_OF_YEAR, 1); } else if (System.currentTimeMillis() >= target.getTimeInMillis()) { target.add(Calendar.DAY_OF_YEAR, 1); } Intent i = createTriggerAlwaysAlarmIntent(trigId); PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager alarmMan = (AlarmManager) getSystemService(ALARM_SERVICE); Log.v(TAG, "LocTrigService: Calculated target time: " + target.getTime().toString()); long alarmTime = target.getTimeInMillis(); /* Convert the alarm time to elapsed real time. * If we dont do this, a time change in the system might * set off all the alarms and a trigger might go off before * we get a chance to cancel it */ long elapsedRT = alarmTime - System.currentTimeMillis(); if (elapsedRT <= 0) { Log.v(TAG, "LocTrigService: negative elapsed realtime - " + "alarm not setting: " + trigId); return; } Log.v(TAG, "LocTrigService: Setting alarm for " + elapsedRT + " millis into the future"); alarmMan.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + elapsedRT, pi); }
From source file:com.newcell.calltext.service.SipNotifications.java
public void showNotificationForMessage(SipMessage msg) { if (!CustomDistribution.supportMessaging()) { return;//from w ww .j av a 2 s. c o m } if (!msg.getFrom().equalsIgnoreCase(viewingRemoteFrom)) { CallerInfo callerInfo = CallerInfo.getCallerInfoFromSipUri(context, msg.getFullFrom()); String from; if (callerInfo != null && callerInfo.contactExists) { from = callerInfo.name; } else { from = callerInfo.phoneNumber; } // String from = SipUri.getDisplayedSimpleContact(msg.getFullFrom()); // Old version // if(from.equalsIgnoreCase(msg.getFullFrom()) && !from.equals(msg.getDisplayName())) { // from = msg.getDisplayName() + " " + from; // } CharSequence tickerText = buildTickerMessage(context, from, msg.getBody()); if (messageNotification == null) { messageNotification = new NotificationCompat.Builder(context); messageNotification.setSmallIcon(SipUri.isPhoneNumber(from) ? R.drawable.stat_notify_sms : android.R.drawable.stat_notify_chat); messageNotification.setTicker(tickerText); messageNotification.setWhen(System.currentTimeMillis()); messageNotification.setDefaults(Notification.DEFAULT_ALL); messageNotification.setAutoCancel(true); messageNotification.setOnlyAlertOnce(true); } Intent notificationIntent = new Intent(SipManager.ACTION_SIP_MESSAGES); notificationIntent.putExtra(SipMessage.FIELD_FROM, msg.getFrom()); notificationIntent.putExtra(SipMessage.FIELD_BODY, msg.getBody()); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); messageNotification.setContentTitle(from); messageNotification.setContentText(msg.getBody()); messageNotification.setContentIntent(contentIntent); notificationManager.notify(MESSAGE_NOTIF_ID, messageNotification.build()); } }