List of usage examples for android.content Intent FLAG_ACTIVITY_CLEAR_TASK
int FLAG_ACTIVITY_CLEAR_TASK
To view the source code for android.content Intent FLAG_ACTIVITY_CLEAR_TASK.
Click Source Link
From source file:org.egov.android.view.activity.UserComplaintActivity.java
private void listComplaints(Event<ApiResponse> event) { lastviewpos = lvcomplaint.getFirstVisiblePosition(); //get offset of first visible view View v = lvcomplaint.getChildAt(0); topOffset = (v == null) ? 0 : v.getTop(); String status = event.getData().getApiStatus().getStatus(); String pagination = event.getData().getApiStatus().isPagination(); String msg = event.getData().getApiStatus().getMessage(); if (page == 1) { listItem = new ArrayList<Complaint>(); }//from w w w. j a v a 2 s .c om if (status.equalsIgnoreCase("success")) { isApiLoaded = true; if (listItem.size() > 5) { listItem.remove(listItem.size() - 1); } try { JSONArray ja = new JSONArray(event.getData().getResponse().toString()); if (ja.length() > 0) { for (int i = 0; i < ja.length(); i++) { JSONObject jo = ja.getJSONObject(i); Complaint item = new Complaint(); item.setCreatedDate(_getValue(jo, "createdDate")); item.setDetails(_getValue(jo, "detail")); item.setComplaintId(_getValue(jo, "crn")); item.setStatus(jo.getString("status")); StorageManager sm = new StorageManager(); Object[] obj = sm.getStorageInfo(UserComplaintActivity.this.getActivity()); String complaintFolderName = obj[0].toString() + "/complaints/" + jo.getString("crn"); File complaintFolder = new File(complaintFolderName); if (jo.getInt("supportDocsSize") == 0) { /*item.setImagePath(complaintFolderName + File.separator + ".thumb_photo_complaint_type.jpg");*/ item.setImagePath(""); } else { item.setImagePath(complaintFolderName + File.separator + ".thumb_photo_" + jo.getInt("supportDocsSize") + ".jpg"); _addDownloadJobs(complaintFolderName, jo); } if (!complaintFolder.exists()) { sm.mkdirs(complaintFolderName); } listItem.add(item); } if (listItem.size() > 5 && !isRefresh) { lvcomplaint.postDelayed(new Runnable() { public void run() { lvcomplaint.setStackFromBottom(true); lvcomplaint.setSelectionFromTop(lastviewpos, topOffset); } }, 100); } if (pagination.equals("true")) { Complaint item = new Complaint(); listItem.add(item); } if (downloadThumbImages.length() > 0) { new ImageDownloaderTask((!isRefresh ? null : getProgressBar()), pagination.equals("true")) .execute(downloadThumbImages); } else { if (!isRefresh) { _displayListView(pagination.equals("true")); } } //ServiceController.getInstance().startJobs(); //_displayListView(pagination.equals("true")); } else if (listItem.size() == 0) { ((TextView) getActivity().findViewById(R.id.user_errMsg)).setVisibility(View.VISIBLE); } } catch (JSONException e) { e.printStackTrace(); } } else { if (msg.matches(".*Invalid access token.*")) { _showMsg("Session expired"); AndroidLibrary.getInstance().getSession().edit().putString("access_token", "").commit(); Intent intent = new Intent(getActivity(), LoginActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); getActivity().startActivity(intent); getActivity().finish(); } else { page = (page > 1) ? page - 1 : 1; _showMsg(msg); } } }
From source file:com.evandroid.musica.fragment.LyricsViewFragment.java
public void checkPreferencesChanges() { boolean screenOn = PreferenceManager.getDefaultSharedPreferences(getActivity()) .getBoolean("pref_force_screen_on", false); boolean dyslexic = PreferenceManager.getDefaultSharedPreferences(getActivity()) .getBoolean("pref_opendyslexic", false); TextSwitcher switcher = (TextSwitcher) getActivity().findViewById(R.id.switcher); View lrcView = getActivity().findViewById(R.id.lrc_view); if (switcher != null) { switcher.setKeepScreenOn(screenOn); if (switcher.getCurrentView() != null) ((TextView) switcher.getCurrentView()).setTypeface( LyricsTextFactory.FontCache.get(dyslexic ? "dyslexic" : "light", getActivity())); View nextView = switcher.getNextView(); if (nextView != null) { ((TextView) nextView).setTypeface( LyricsTextFactory.FontCache.get(dyslexic ? "dyslexic" : "light", getActivity())); }/*from w w w . j a v a2s . c o m*/ } if (lrcView != null) lrcView.setKeepScreenOn(screenOn); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); TypedValue outValue = new TypedValue(); getActivity().getTheme().resolveAttribute(R.attr.themeName, outValue, false); if ("Night".equals(outValue.string) != NightTimeVerifier.check(getActivity()) || "Dark".equals(outValue.string) == sharedPrefs.getString("pref_theme", "0").equals("0")) { getActivity().finish(); Intent intent = new Intent(getActivity(), MainLyricActivity.class); intent.setAction("android.intent.action.MAIN"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); } }
From source file:com.google.samples.apps.sergio.service.SessionAlarmService.java
private void notifySession(final long sessionStart, final long alarmOffset) { long currentTime = UIUtils.getCurrentTime(this); final long intervalEnd = sessionStart + MILLI_TEN_MINUTES; LOGD(TAG, "Considering notifying for time interval."); LOGD(TAG, " Interval start: " + sessionStart + "=" + (new Date(sessionStart)).toString()); LOGD(TAG, " Interval end: " + intervalEnd + "=" + (new Date(intervalEnd)).toString()); LOGD(TAG, " Current time is: " + currentTime + "=" + (new Date(currentTime)).toString()); if (sessionStart < currentTime) { LOGD(TAG, "Skipping session notification (too late -- time interval already started)"); return;//from w ww . j av a 2 s . co m } if (!PrefUtils.shouldShowSessionReminders(this)) { // skip if disabled in settings LOGD(TAG, "Skipping session notification for sessions. Disabled in settings."); return; } // Avoid repeated notifications. if (alarmOffset == UNDEFINED_ALARM_OFFSET && UIUtils.isNotificationFiredForBlock(this, ScheduleContract.Blocks.generateBlockId(sessionStart, intervalEnd))) { LOGD(TAG, "Skipping session notification (already notified)"); return; } final ContentResolver cr = getContentResolver(); LOGD(TAG, "Looking for sessions in interval " + sessionStart + " - " + intervalEnd); Cursor c = cr.query(ScheduleContract.Sessions.CONTENT_MY_SCHEDULE_URI, SessionDetailQuery.PROJECTION, ScheduleContract.Sessions.STARTING_AT_TIME_INTERVAL_SELECTION, ScheduleContract.Sessions.buildAtTimeIntervalArgs(sessionStart, intervalEnd), null); int starredCount = c.getCount(); LOGD(TAG, "# starred sessions in that interval: " + c.getCount()); String singleSessionId = null; String singleSessionRoomId = null; ArrayList<String> starredSessionTitles = new ArrayList<String>(); while (c.moveToNext()) { singleSessionId = c.getString(SessionDetailQuery.SESSION_ID); singleSessionRoomId = c.getString(SessionDetailQuery.ROOM_ID); starredSessionTitles.add(c.getString(SessionDetailQuery.SESSION_TITLE)); LOGD(TAG, "-> Title: " + c.getString(SessionDetailQuery.SESSION_TITLE)); } if (starredCount < 1) { return; } // Generates the pending intent which gets fired when the user taps on the notification. // NOTE: Use TaskStackBuilder to comply with Android's design guidelines // related to navigation from notifications. Intent baseIntent = new Intent(this, MyScheduleActivity.class); baseIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); TaskStackBuilder taskBuilder = TaskStackBuilder.create(this).addNextIntent(baseIntent); // For a single session, tapping the notification should open the session details (b/15350787) if (starredCount == 1) { taskBuilder.addNextIntent( new Intent(Intent.ACTION_VIEW, ScheduleContract.Sessions.buildSessionUri(singleSessionId))); } PendingIntent pi = taskBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT); final Resources res = getResources(); String contentText; int minutesLeft = (int) (sessionStart - currentTime + 59000) / 60000; if (minutesLeft < 1) { minutesLeft = 1; } if (starredCount == 1) { contentText = res.getString(R.string.session_notification_text_1, minutesLeft); } else { contentText = res.getQuantityString(R.plurals.session_notification_text, starredCount - 1, minutesLeft, starredCount - 1); } NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this) .setContentTitle(starredSessionTitles.get(0)).setContentText(contentText) .setColor(getResources().getColor(R.color.theme_primary)) .setTicker(res.getQuantityString(R.plurals.session_notification_ticker, starredCount, starredCount)) .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setLights(SessionAlarmService.NOTIFICATION_ARGB_COLOR, SessionAlarmService.NOTIFICATION_LED_ON_MS, SessionAlarmService.NOTIFICATION_LED_OFF_MS) .setSmallIcon(R.drawable.ic_stat_notification).setContentIntent(pi) .setPriority(Notification.PRIORITY_MAX).setAutoCancel(true); if (minutesLeft > 5) { notifBuilder.addAction(R.drawable.ic_alarm_holo_dark, String.format(res.getString(R.string.snooze_x_min), 5), createSnoozeIntent(sessionStart, intervalEnd, 5)); } if (starredCount == 1 && PrefUtils.isAttendeeAtVenue(this)) { notifBuilder.addAction(R.drawable.ic_map_holo_dark, res.getString(R.string.title_map), createRoomMapIntent(singleSessionRoomId)); } String bigContentTitle; if (starredCount == 1 && starredSessionTitles.size() > 0) { bigContentTitle = starredSessionTitles.get(0); } else { bigContentTitle = res.getQuantityString(R.plurals.session_notification_title, starredCount, minutesLeft, starredCount); } NotificationCompat.InboxStyle richNotification = new NotificationCompat.InboxStyle(notifBuilder) .setBigContentTitle(bigContentTitle); // Adds starred sessions starting at this time block to the notification. for (int i = 0; i < starredCount; i++) { richNotification.addLine(starredSessionTitles.get(i)); } NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); LOGD(TAG, "Now showing notification."); nm.notify(NOTIFICATION_ID, richNotification.build()); }
From source file:cn.moon.superwechat.ui.MainActivity.java
/** * show the dialog when user met some exception: such as login on another device, user removed or user forbidden *//*from ww w.j a va 2 s .c om*/ private void showExceptionDialog(String exceptionType) { isExceptionDialogShow = true; SuperWeChatHelper.getInstance().logout(false, null); String st = getResources().getString(R.string.Logoff_notification); if (!MainActivity.this.isFinishing()) { // clear up global variables try { if (exceptionBuilder == null) exceptionBuilder = new AlertDialog.Builder(MainActivity.this); exceptionBuilder.setTitle(st); exceptionBuilder.setMessage(getExceptionMessageId(exceptionType)); exceptionBuilder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); exceptionBuilder = null; isExceptionDialogShow = false; finish(); Intent intent = new Intent(MainActivity.this, LoginActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } }); exceptionBuilder.setCancelable(false); exceptionBuilder.create().show(); isConflict = true; } catch (Exception e) { EMLog.e(TAG, "---------color conflictBuilder error" + e.getMessage()); } } }
From source file:cn.ucai.wechat.ui.MainActivity.java
/** * show the dialog when user met some exception: such as login on another device, user removed or user forbidden *///from w ww . j av a2 s. c om private void showExceptionDialog(String exceptionType) { isExceptionDialogShow = true; WeChatHelper.getInstance().logout(false, null); String st = getResources().getString(R.string.Logoff_notification); if (!MainActivity.this.isFinishing()) { // clear up global variables try { if (exceptionBuilder == null) exceptionBuilder = new AlertDialog.Builder(MainActivity.this); exceptionBuilder.setTitle(st); exceptionBuilder.setMessage(getExceptionMessageId(exceptionType)); exceptionBuilder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); exceptionBuilder = null; isExceptionDialogShow = false; finish(); Intent intent = new Intent(MainActivity.this, LoginActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } }); exceptionBuilder.setCancelable(false); exceptionBuilder.create().show(); isConflict = true; } catch (Exception e) { EMLog.e(TAG, "---------color conflictBuilder error" + e.getMessage()); } } }
From source file:cn.wyl.superwechat.ui.MainActivity.java
/** * show the dialog when user logged into another device *//*from www . j a va 2 s . com*/ private void showConflictDialog() { isConflictDialogShow = true; SuperWeChatHelper.getInstance().logout(false, null); String st = getResources().getString(R.string.Logoff_notification); if (!MainActivity.this.isFinishing()) { // clear up global variables try { if (conflictBuilder == null) conflictBuilder = new AlertDialog.Builder(MainActivity.this); conflictBuilder.setTitle(st); conflictBuilder.setMessage(R.string.connect_conflict); conflictBuilder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); conflictBuilder = null; finish(); Intent intent = new Intent(MainActivity.this, LoginActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } }); conflictBuilder.setCancelable(false); conflictBuilder.create().show(); isConflict = true; } catch (Exception e) { EMLog.e(TAG, "---------color conflictBuilder error" + e.getMessage()); } } }
From source file:in.codehex.arrow.MainActivity.java
/** * Checks whether the user has logged in. If not, Login Activity is started. *///from ww w. j a v a2 s .com private boolean loginCheck() { if (!userPreferences.contains(Config.KEY_PREF_IMEI)) { intent = new Intent(this, LoginActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); return false; } else return true; }
From source file:com.daskiworks.ghwatch.backend.UnreadNotificationsService.java
protected void fireAndroidNotification(NotificationStream newStream, NotificationStream oldStream) { if (newStream == null || !PreferencesUtils.getBoolean(context, PreferencesUtils.PREF_NOTIFY, true)) return;//from w w w . j a v a2s .c o m Log.d(TAG, "fireAndroidNotification count before filter " + newStream.size()); newStream = filterForAndroidNotification(newStream); Log.d(TAG, "fireAndroidNotification count after filter " + newStream.size()); if (newStream.isNewNotification(oldStream)) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.github_notification) .setContentTitle(context.getString(R.string.an_title_more)) .setPriority(NotificationCompat.PRIORITY_DEFAULT); mBuilder.setAutoCancel(true); if (newStream.size() > 1) mBuilder.setNumber(newStream.size()); boolean allFromOne = newStream.allNotificationsFromSameRepository(); if (newStream.size() == 1 || allFromOne) { // only one repository Notification n = newStream.get(0); Bitmap b = ImageLoader.getInstance(context).loadImageWithFileLevelCache(n.getRepositoryAvatarUrl()); if (b != null) { mBuilder.setLargeIcon(b); } else { mBuilder.setLargeIcon( BitmapFactory.decodeResource(context.getResources(), R.drawable.github_notification)); } mBuilder.setContentText(n.getRepositoryFullName()); } else { mBuilder.setLargeIcon( BitmapFactory.decodeResource(context.getResources(), R.drawable.github_notification)); } Intent resultIntent = null; if (newStream.size() == 1) { mBuilder.setContentTitle(context.getString(R.string.an_title_one)); Notification n = newStream.get(0); mBuilder.setContentText(n.getRepositoryFullName() + ": " + n.getSubjectTitle()); NotificationCompat.BigTextStyle btStyle = new NotificationCompat.BigTextStyle(); btStyle.bigText(n.getSubjectTitle()); btStyle.setSummaryText(n.getRepositoryFullName()); mBuilder.setStyle(btStyle); Intent actionIntent = new Intent(context, MarkNotifiationAsReadReceiver.class); actionIntent.putExtra(MarkNotifiationAsReadReceiver.INTENT_EXTRA_KEY_ID, n.getId()); mBuilder.addAction(R.drawable.ic_action_dismis_all, context.getString(R.string.action_mark_read), PendingIntent.getBroadcast(context, 0, actionIntent, PendingIntent.FLAG_UPDATE_CURRENT)); resultIntent = new Intent(context, MainActivity.class); } else { NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); for (Notification n : newStream) { if (allFromOne) { inboxStyle.addLine(n.getSubjectTitle()); } else { inboxStyle.addLine(n.getRepositoryFullName() + ": " + n.getSubjectTitle()); } } if (allFromOne) inboxStyle.setSummaryText(newStream.get(0).getRepositoryFullName()); else inboxStyle.setSummaryText(" "); mBuilder.setStyle(inboxStyle); Intent actionIntent = new Intent(context, MainActivity.class); actionIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); actionIntent.setAction(MainActivity.INTENT_ACTION_DISMISS_ALL); mBuilder.addAction(R.drawable.ic_action_dismis_all, context.getString(R.string.action_all_read), PendingIntent.getActivity(context, 0, actionIntent, 0)); resultIntent = new Intent(context, MainActivity.class); } resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); resultIntent.setAction(MainActivity.INTENT_ACTION_SHOW); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0); mBuilder.setContentIntent(resultPendingIntent); String nsound = PreferencesUtils.getString(context, PreferencesUtils.PREF_NOTIFY_SOUND, null); Log.d(TAG, "Notification sound from preference: " + nsound); if (nsound != null) { mBuilder.setSound(Uri.parse(nsound)); } if (PreferencesUtils.getBoolean(context, PreferencesUtils.PREF_NOTIFY_VIBRATE, true)) { mBuilder.setVibrate(new long[] { 0, 300, 100, 150, 100, 150 }); } mBuilder.setLights(0xffffffff, 100, 4000); // mId allows you to update the notification later on. Utils.getNotificationManager(context).notify(ANDROID_NOTIFICATION_ID, mBuilder.build()); ActivityTracker.sendEvent(context, ActivityTracker.CAT_NOTIF, "new_notif", "notif count: " + newStream.size(), Long.valueOf(newStream.size())); } else if (newStream.isEmpty()) { // #54 dismiss previous android notification if no any Github notification is available (as it was read on another device) Utils.getNotificationManager(context).cancel(ANDROID_NOTIFICATION_ID); } }
From source file:com.miz.mizuu.fragments.MovieDetailsFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: if (getActivity().getIntent().getExtras().getBoolean("isFromWidget")) { Intent i = new Intent(Intent.ACTION_VIEW); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); i.putExtra("startup", String.valueOf(Main.MOVIES)); i.setClass(mContext, Main.class); startActivity(i);/*ww w .j ava 2 s. c om*/ } getActivity().finish(); return true; case R.id.share: Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, "http://www.imdb.com/title/" + mMovie.getImdbId()); startActivity(intent); return true; case R.id.change_cover: searchCover(); return true; case R.id.editMovie: editMovie(); return true; case R.id.identify: identifyMovie(); return true; case R.id.watched: watched(true); return true; case R.id.trailer: VideoUtils.playTrailer(getActivity(), mMovie); return true; case R.id.watch_list: watchList(); return true; case R.id.movie_fav: favAction(); return true; case R.id.delete_movie: deleteMovie(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.saarang.samples.apps.iosched.service.SessionAlarmService.java
private void notifySession(final long sessionStart, final long alarmOffset) { long currentTime = UIUtils.getCurrentTime(this); final long intervalEnd = sessionStart + MILLI_TEN_MINUTES; LogUtils.LOGD(TAG, "Considering notifying for time interval."); LogUtils.LOGD(TAG, " Interval start: " + sessionStart + "=" + (new Date(sessionStart)).toString()); LogUtils.LOGD(TAG, " Interval end: " + intervalEnd + "=" + (new Date(intervalEnd)).toString()); LogUtils.LOGD(TAG, " Current time is: " + currentTime + "=" + (new Date(currentTime)).toString()); if (sessionStart < currentTime) { LogUtils.LOGD(TAG, "Skipping session notification (too late -- time interval already started)"); return;/*from ww w . j a va 2 s . c o m*/ } if (!PrefUtils.shouldShowSessionReminders(this)) { // skip if disabled in settings LogUtils.LOGD(TAG, "Skipping session notification for sessions. Disabled in settings."); return; } // Avoid repeated notifications. if (alarmOffset == UNDEFINED_ALARM_OFFSET && UIUtils.isNotificationFiredForBlock(this, ScheduleContract.Blocks.generateBlockId(sessionStart, intervalEnd))) { LogUtils.LOGD(TAG, "Skipping session notification (already notified)"); return; } final ContentResolver cr = getContentResolver(); LogUtils.LOGD(TAG, "Looking for sessions in interval " + sessionStart + " - " + intervalEnd); Cursor c = cr.query(ScheduleContract.Sessions.CONTENT_MY_SCHEDULE_URI, SessionDetailQuery.PROJECTION, ScheduleContract.Sessions.STARTING_AT_TIME_INTERVAL_SELECTION, ScheduleContract.Sessions.buildAtTimeIntervalArgs(sessionStart, intervalEnd), null); int starredCount = c.getCount(); LogUtils.LOGD(TAG, "# starred sessions in that interval: " + c.getCount()); String singleSessionId = null; String singleSessionRoomId = null; ArrayList<String> starredSessionTitles = new ArrayList<String>(); while (c.moveToNext()) { singleSessionId = c.getString(SessionDetailQuery.SESSION_ID); singleSessionRoomId = c.getString(SessionDetailQuery.ROOM_ID); starredSessionTitles.add(c.getString(SessionDetailQuery.SESSION_TITLE)); LogUtils.LOGD(TAG, "-> Title: " + c.getString(SessionDetailQuery.SESSION_TITLE)); } if (starredCount < 1) { return; } // Generates the pending intent which gets fired when the user taps on the notification. // NOTE: Use TaskStackBuilder to comply with Android's design guidelines // related to navigation from notifications. Intent baseIntent = new Intent(this, MyScheduleActivity.class); baseIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); TaskStackBuilder taskBuilder = TaskStackBuilder.create(this).addNextIntent(baseIntent); // For a single session, tapping the notification should open the session details (b/15350787) if (starredCount == 1) { taskBuilder.addNextIntent( new Intent(Intent.ACTION_VIEW, ScheduleContract.Sessions.buildSessionUri(singleSessionId))); } PendingIntent pi = taskBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT); final Resources res = getResources(); String contentText; int minutesLeft = (int) (sessionStart - currentTime + 59000) / 60000; if (minutesLeft < 1) { minutesLeft = 1; } if (starredCount == 1) { contentText = res.getString(com.saarang.samples.apps.iosched.R.string.session_notification_text_1, minutesLeft); } else { contentText = res.getQuantityString( com.saarang.samples.apps.iosched.R.plurals.session_notification_text, starredCount - 1, minutesLeft, starredCount - 1); } NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this) .setContentTitle(starredSessionTitles.get(0)).setContentText(contentText) .setColor(getResources().getColor(com.saarang.samples.apps.iosched.R.color.theme_primary)) .setTicker(res .getQuantityString(com.saarang.samples.apps.iosched.R.plurals.session_notification_ticker, starredCount, starredCount)) .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .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).setContentIntent(pi) .setPriority(Notification.PRIORITY_MAX).setAutoCancel(true); if (minutesLeft > 5) { notifBuilder.addAction(com.saarang.samples.apps.iosched.R.drawable.ic_alarm_holo_dark, String.format(res.getString(com.saarang.samples.apps.iosched.R.string.snooze_x_min), 5), createSnoozeIntent(sessionStart, intervalEnd, 5)); } if (starredCount == 1 && PrefUtils.isAttendeeAtVenue(this)) { notifBuilder.addAction(com.saarang.samples.apps.iosched.R.drawable.ic_map_holo_dark, res.getString(com.saarang.samples.apps.iosched.R.string.title_map), createRoomMapIntent(singleSessionRoomId)); } String bigContentTitle; if (starredCount == 1 && starredSessionTitles.size() > 0) { bigContentTitle = starredSessionTitles.get(0); } else { bigContentTitle = res.getQuantityString( com.saarang.samples.apps.iosched.R.plurals.session_notification_title, starredCount, minutesLeft, starredCount); } NotificationCompat.InboxStyle richNotification = new NotificationCompat.InboxStyle(notifBuilder) .setBigContentTitle(bigContentTitle); // Adds starred sessions starting at this time block to the notification. for (int i = 0; i < starredCount; i++) { richNotification.addLine(starredSessionTitles.get(i)); } NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); LogUtils.LOGD(TAG, "Now showing notification."); nm.notify(NOTIFICATION_ID, richNotification.build()); }