List of usage examples for android.app Notification PRIORITY_MIN
int PRIORITY_MIN
To view the source code for android.app Notification PRIORITY_MIN.
Click Source Link
From source file:com.jmstudios.redmoon.presenter.ScreenFilterPresenter.java
private void refreshForegroundNotification() { if (isOff()) { return;//from w w w .jav a2 s . com } Context context = mView.getContext(); ProfilesModel profilesModel = new ProfilesModel(context); String title = context.getString(R.string.app_name); int color = context.getResources().getColor(R.color.color_primary); Intent offCommand = mFilterCommandFactory.createCommand(ScreenFilterService.COMMAND_OFF); int smallIconResId = R.drawable.notification_icon_half_moon; String contentText; int pauseOrResumeDrawableResId; Intent pauseOrResumeCommand; String pauseOrResumeActionText; if (isPaused()) { Log.d(TAG, "Creating notification while in pause state"); contentText = context.getString(R.string.paused); pauseOrResumeDrawableResId = R.drawable.ic_play; pauseOrResumeCommand = mFilterCommandFactory.createCommand(ScreenFilterService.COMMAND_ON); pauseOrResumeActionText = context.getString(R.string.resume_action); } else { Log.d(TAG, "Creating notification while NOT in pause state"); contentText = context.getString(R.string.running); pauseOrResumeDrawableResId = R.drawable.ic_pause; pauseOrResumeCommand = mFilterCommandFactory.createCommand(ScreenFilterService.COMMAND_PAUSE); pauseOrResumeActionText = context.getString(R.string.pause_action); } Intent shadesActivityIntent = new Intent(context, ShadesActivity.class); shadesActivityIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pauseOrResumePI = PendingIntent.getService(context, REQUEST_CODE_ACTION_PAUSE_OR_RESUME, pauseOrResumeCommand, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent settingsPI = PendingIntent.getActivity(context, REQUEST_CODE_ACTION_SETTINGS, shadesActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT); Intent nextProfileIntent = new Intent(context, NextProfileCommandReceiver.class); PendingIntent nextProfilePI = PendingIntent.getBroadcast(context, REQUEST_CODE_NEXT_PROFILE, nextProfileIntent, 0); mNotificationBuilder = new NotificationCompat.Builder(mContext); mNotificationBuilder.setSmallIcon(smallIconResId).setContentTitle(title).setContentText(contentText) .setColor(color).setContentIntent(settingsPI) .addAction(pauseOrResumeDrawableResId, pauseOrResumeActionText, pauseOrResumePI) .addAction(R.drawable.ic_next_profile, ProfilesHelper.getProfileName(profilesModel, mSettingsModel.getProfile(), context), nextProfilePI) .setPriority(Notification.PRIORITY_MIN); if (isPaused()) { Log.d(TAG, "Creating a dismissible notification"); NotificationManager mNotificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(NOTIFICATION_ID, mNotificationBuilder.build()); } else { Log.d(TAG, "Creating a persistent notification"); mServiceController.startForeground(NOTIFICATION_ID, mNotificationBuilder.build()); } }
From source file:com.bullmobi.message.services.BathService.java
/** * <p>NOT SYNCHRONIZED!</p>//from www. ja va 2 s . co m * Builds fresh notification with all {@link ChildService children services}'s * {@link com.bullmobi.message.services.BathService.ChildService#getLabel() labels} in. * Content intent starts {@link com.bullmobi.message.ui.activities.MainActivity}. */ private Notification buildNotification() { boolean empty = true; StringBuilder sb = new StringBuilder(); String divider = getString(R.string.settings_multi_list_divider); for (ChildService child : mMap.values()) { if (!empty) { sb.append(divider); } sb.append(child.getLabel()); empty = false; } String contentText = sb.toString(); if (contentText.length() > 0) { contentText = contentText.charAt(0) + contentText.substring(1).toLowerCase(); } PendingIntent pendingIntent = PendingIntent.getActivity(this, App.ID_NOTIFY_BATH, new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setContentTitle(getString(R.string.service_bath)).setContentText(contentText) .setContentIntent(pendingIntent).setSmallIcon(R.drawable.stat_easynotification) .setPriority(Notification.PRIORITY_MIN).setColor(App.ACCENT_COLOR); return builder.build(); }
From source file:org.smssecure.smssecure.service.KeyCachingService.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void foregroundServiceModern() { Log.w("KeyCachingService", "foregrounding KCS"); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle(getString(R.string.KeyCachingService_passphrase_cached)); builder.setContentText(getString(R.string.KeyCachingService_silence_passphrase_cached)); builder.setSmallIcon(R.drawable.icon_cached); builder.setWhen(0);/*from w w w . ja v a 2s.co m*/ builder.setPriority(Notification.PRIORITY_MIN); builder.addAction(R.drawable.ic_menu_lock_dark, getString(R.string.KeyCachingService_lock), buildLockIntent()); builder.setContentIntent(buildLaunchIntent()); stopForeground(true); startForeground(SERVICE_RUNNING_ID, builder.build()); }
From source file:com.tingtingapps.securesms.service.KeyCachingService.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void foregroundServiceModern() { Log.w("KeyCachingService", "foregrounding KCS"); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle(getString(com.tingtingapps.securesms.R.string.KeyCachingService_passphrase_cached)); builder.setContentText(//www . j a v a 2s .com getString(com.tingtingapps.securesms.R.string.KeyCachingService_textsecure_passphrase_cached)); builder.setSmallIcon(com.tingtingapps.securesms.R.drawable.icon_cached); builder.setWhen(0); builder.setPriority(Notification.PRIORITY_MIN); builder.addAction(com.tingtingapps.securesms.R.drawable.ic_menu_lock_holo_dark, getString(com.tingtingapps.securesms.R.string.KeyCachingService_lock), buildLockIntent()); builder.setContentIntent(buildLaunchIntent()); stopForeground(true); startForeground(SERVICE_RUNNING_ID, builder.build()); }
From source file:org.thoughtcrime.SMP.service.KeyCachingService.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void foregroundServiceModern() { Log.w("KeyCachingService", "foregrounding KCS"); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle(getString(R.string.KeyCachingService_passphrase_cached)); builder.setContentText(getString(R.string.KeyCachingService_textsecure_passphrase_cached)); builder.setSmallIcon(R.drawable.icon_cached); builder.setWhen(0);// w w w . j a va 2s. com builder.setPriority(Notification.PRIORITY_MIN); builder.addAction(R.drawable.ic_menu_lock_holo_dark, getString(R.string.KeyCachingService_lock), buildLockIntent()); builder.setContentIntent(buildLaunchIntent()); stopForeground(true); startForeground(SERVICE_RUNNING_ID, builder.build()); }
From source file:org.awesomeapp.messenger.service.RemoteImService.java
private Notification getForegroundNotification() { mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); ;//from w w w. j ava 2 s . c om mNotifyBuilder = new NotificationCompat.Builder(this).setContentTitle(getString(R.string.app_name)) .setSmallIcon(R.drawable.notify_zom); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) { mNotifyBuilder.setPriority(Notification.PRIORITY_MIN); } mNotifyBuilder.setOngoing(true); mNotifyBuilder.setWhen(System.currentTimeMillis()); Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent launchIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0); mNotifyBuilder.setContentIntent(launchIntent); mNotifyBuilder.setContentText(getString(R.string.app_unlocked)); return mNotifyBuilder.build(); }
From source file:com.linkbubble.MainService.java
private void showUnhideHiddenNotification() { Intent unhideIntent = new Intent(this, NotificationUnhideActivity.class); unhideIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent unhidePendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), unhideIntent, PendingIntent.FLAG_UPDATE_CURRENT); /*Intent showContentViewIntent = new Intent(this, NotificationShowContentActivity.class); showContentViewIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent showContentViewPendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), showContentViewIntent, PendingIntent.FLAG_UPDATE_CURRENT);*/ Intent closeAllIntent = new Intent(this, NotificationCloseAllActivity.class); closeAllIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent closeAllPendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), closeAllIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat).setPriority(Notification.PRIORITY_MIN) .setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.notification_unhide_summary)).setLocalOnly(true) //.addAction(R.drawable.ic_action_eye_open_dark, getString(R.string.notification_action_unhide), unhidePendingIntent) //.addAction(R.drawable.ic_action_cancel_dark, getString(R.string.notification_action_close_all), closeAllPendingIntent) .addAction(// w ww.ja v a2s.c o m Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT ? R.drawable.ic_action_cancel_white : R.drawable.ic_action_cancel_dark, getString(R.string.notification_action_close_all), closeAllPendingIntent) .setContentIntent(unhidePendingIntent); /*MainController controller = MainController.get(); if (null != controller && null != controller.mBubbleFlowDraggable) { if (!controller.mBubbleFlowDraggable.isExpanded()) { notificationBuilder .addAction(R.drawable.ic_stat, getString(R.string.notification_expand), showContentViewPendingIntent) .setContentText(getString(R.string.notification_unhide_expand_summary)); } }*/ NotificationManagerCompat.from(this).cancelAll(); startForeground(1, notificationBuilder.build()); //Log.d("blerg", "showUnhideHiddenNotification()"); }
From source file:com.android.calendar.alerts.AlertService.java
public static boolean generateAlerts(Context context, NotificationMgr nm, AlarmManagerInterface alarmMgr, SharedPreferences prefs, Cursor alertCursor, final long currentTime, final int maxNotifications) { if (DEBUG) {//from w ww . java 2 s .c o m Log.d(TAG, "alertCursor count:" + alertCursor.getCount()); } // Process the query results and bucketize events. ArrayList<NotificationInfo> highPriorityEvents = new ArrayList<NotificationInfo>(); ArrayList<NotificationInfo> mediumPriorityEvents = new ArrayList<NotificationInfo>(); ArrayList<NotificationInfo> lowPriorityEvents = new ArrayList<NotificationInfo>(); int numFired = processQuery(alertCursor, context, currentTime, highPriorityEvents, mediumPriorityEvents, lowPriorityEvents); if (highPriorityEvents.size() + mediumPriorityEvents.size() + lowPriorityEvents.size() == 0) { nm.cancelAll(); return true; } long nextRefreshTime = Long.MAX_VALUE; int currentNotificationId = 1; NotificationPrefs notificationPrefs = new NotificationPrefs(context, prefs, (numFired == 0)); // If there are more high/medium priority events than we can show, bump some to // the low priority digest. redistributeBuckets(highPriorityEvents, mediumPriorityEvents, lowPriorityEvents, maxNotifications); // Post the individual higher priority events (future and recently started // concurrent events). Order these so that earlier start times appear higher in // the notification list. for (int i = 0; i < highPriorityEvents.size(); i++) { NotificationInfo info = highPriorityEvents.get(i); String summaryText = AlertUtils.formatTimeLocation(context, info.startMillis, info.allDay, info.location); postNotification(info, summaryText, context, true, notificationPrefs, nm, currentNotificationId++); // Keep concurrent events high priority (to appear higher in the notification list) // until 15 minutes into the event. nextRefreshTime = Math.min(nextRefreshTime, getNextRefreshTime(info, currentTime)); } // Post the medium priority events (concurrent events that started a while ago). // Order these so more recent start times appear higher in the notification list. // // TODO: Post these with the same notification priority level as the higher priority // events, so that all notifications will be co-located together. for (int i = mediumPriorityEvents.size() - 1; i >= 0; i--) { NotificationInfo info = mediumPriorityEvents.get(i); // TODO: Change to a relative time description like: "Started 40 minutes ago". // This requires constant refreshing to the message as time goes. String summaryText = AlertUtils.formatTimeLocation(context, info.startMillis, info.allDay, info.location); postNotification(info, summaryText, context, false, notificationPrefs, nm, currentNotificationId++); // Refresh when concurrent event ends so it will drop into the expired digest. nextRefreshTime = Math.min(nextRefreshTime, getNextRefreshTime(info, currentTime)); } // Post the low priority events as 1 combined notification. int numLowPriority = lowPriorityEvents.size(); if (numLowPriority > 0) { String expiredDigestTitle = getDigestTitle(lowPriorityEvents); NotificationWrapper notification; if (numLowPriority == 1) { // If only 1 expired event, display an "old-style" basic alert. NotificationInfo info = lowPriorityEvents.get(0); String summaryText = AlertUtils.formatTimeLocation(context, info.startMillis, info.allDay, info.location); notification = AlertReceiver.makeBasicNotification(context, info.eventName, summaryText, info.startMillis, info.endMillis, info.eventId, AlertUtils.EXPIRED_GROUP_NOTIFICATION_ID, false, Notification.PRIORITY_MIN); } else { // Multiple expired events are listed in a digest. notification = AlertReceiver.makeDigestNotification(context, lowPriorityEvents, expiredDigestTitle, false); } // Add options for a quiet update. addNotificationOptions(notification, true, expiredDigestTitle, notificationPrefs.getDefaultVibrate(), notificationPrefs.getRingtoneAndSilence(), false); /* Do not show the LED for the expired events. */ if (DEBUG) { Log.d(TAG, "Quietly posting digest alarm notification, numEvents:" + numLowPriority + ", notificationId:" + AlertUtils.EXPIRED_GROUP_NOTIFICATION_ID); } // Post the new notification for the group. nm.notify(AlertUtils.EXPIRED_GROUP_NOTIFICATION_ID, notification); } else { nm.cancel(AlertUtils.EXPIRED_GROUP_NOTIFICATION_ID); if (DEBUG) { Log.d(TAG, "No low priority events, canceling the digest notification."); } } // Remove the notifications that are hanging around from the previous refresh. if (currentNotificationId <= maxNotifications) { nm.cancelAllBetween(currentNotificationId, maxNotifications); if (DEBUG) { Log.d(TAG, "Canceling leftover notification IDs " + currentNotificationId + "-" + maxNotifications); } } // Schedule the next silent refresh time so notifications will change // buckets (eg. drop into expired digest, etc). if (nextRefreshTime < Long.MAX_VALUE && nextRefreshTime > currentTime) { AlertUtils.scheduleNextNotificationRefresh(context, alarmMgr, nextRefreshTime); if (DEBUG) { long minutesBeforeRefresh = (nextRefreshTime - currentTime) / MINUTE_MS; Time time = new Time(); time.set(nextRefreshTime); String msg = String.format("Scheduling next notification refresh in %d min at: " + "%d:%02d", minutesBeforeRefresh, time.hour, time.minute); Log.d(TAG, msg); } } else if (nextRefreshTime < currentTime) { Log.e(TAG, "Illegal state: next notification refresh time found to be in the past."); } // Flushes old fired alerts from internal storage, if needed. AlertUtils.flushOldAlertsFromInternalStorage(context); return true; }
From source file:com.ubergeek42.WeechatAndroid.service.RelayServiceBackbone.java
/** build notification without displaying it * * @param tickerText text that flashes a bit, can be null * @param content text that appears under title * @param intent intent that's executed on notification click, can be null * @return built notification *//*from w ww .j a va2 s . co m*/ @TargetApi(16) private Notification buildNotification(@Nullable String tickerText, @NonNull String content, @Nullable PendingIntent intent) { if (DEBUG_NOTIFICATIONS) logger.debug("buildNotification({}, {}, {})", new Object[] { tickerText, content, intent }); PendingIntent contentIntent; contentIntent = (intent != null) ? intent : PendingIntent.getActivity(this, 0, new Intent(this, WeechatActivity.class), PendingIntent.FLAG_CANCEL_CURRENT); int icon; if (!isConnection(AUTHENTICATED)) { if (isConnection(CONNECTING)) icon = R.drawable.ic_connecting; else icon = R.drawable.ic_disconnected; } else if (hot_count == 0) icon = R.drawable.ic_connected; else icon = R.drawable.ic_hot; NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentIntent(contentIntent).setSmallIcon(icon) .setContentTitle("WeechatAndroid v" + BuildConfig.VERSION_NAME).setContentText(content) .setWhen(System.currentTimeMillis()); if (prefs.getBoolean(PREF_NOTIFICATION_TICKER, true)) { builder.setTicker(tickerText); } Notification notification = builder.build(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { notification.priority = Notification.PRIORITY_MIN; } notification.flags |= Notification.FLAG_ONGOING_EVENT; return notification; }
From source file:com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPushIntentService.java
private int getPriorityOfMessage(MFPInternalPushMessage message) { String priorityFromServer = message.getPriority(); MFPPushNotificationOptions options = MFPPush.getInstance().getNotificationOptions(); int priorityPreSetValue = 0; if (options != null && options.getPriority() != null) { priorityPreSetValue = options.getPriority().getValue(); }/*www . j av a 2s.c o m*/ if (priorityFromServer != null) { if (priorityFromServer.equalsIgnoreCase(MFPPushConstants.PRIORITY_MAX)) { return Notification.PRIORITY_MAX; } else if (priorityFromServer.equalsIgnoreCase(MFPPushConstants.PRIORITY_MIN)) { return Notification.PRIORITY_MIN; } else if (priorityFromServer.equalsIgnoreCase(MFPPushConstants.PRIORITY_HIGH)) { return Notification.PRIORITY_HIGH; } else if (priorityFromServer.equalsIgnoreCase(MFPPushConstants.PRIORITY_LOW)) { return Notification.PRIORITY_LOW; } } else if (priorityPreSetValue != 0) { return priorityPreSetValue; } return Notification.PRIORITY_DEFAULT; }