Java Code Examples for android.app.Notification#PRIORITY_MAX
The following examples show how to use
android.app.Notification#PRIORITY_MAX .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RankingHelper.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public void updateNotificationChannel(String pkg, int uid, NotificationChannel updatedChannel, boolean fromUser) { Preconditions.checkNotNull(updatedChannel); Preconditions.checkNotNull(updatedChannel.getId()); Record r = getOrCreateRecord(pkg, uid); if (r == null) { throw new IllegalArgumentException("Invalid package"); } NotificationChannel channel = r.channels.get(updatedChannel.getId()); if (channel == null || channel.isDeleted()) { throw new IllegalArgumentException("Channel does not exist"); } if (updatedChannel.getLockscreenVisibility() == Notification.VISIBILITY_PUBLIC) { updatedChannel.setLockscreenVisibility(Ranking.VISIBILITY_NO_OVERRIDE); } if (!fromUser) { updatedChannel.unlockFields(updatedChannel.getUserLockedFields()); } if (fromUser) { updatedChannel.lockFields(channel.getUserLockedFields()); lockFieldsForUpdate(channel, updatedChannel); } r.channels.put(updatedChannel.getId(), updatedChannel); if (NotificationChannel.DEFAULT_CHANNEL_ID.equals(updatedChannel.getId())) { // copy settings to app level so they are inherited by new channels // when the app migrates r.importance = updatedChannel.getImportance(); r.priority = updatedChannel.canBypassDnd() ? Notification.PRIORITY_MAX : Notification.PRIORITY_DEFAULT; r.visibility = updatedChannel.getLockscreenVisibility(); r.showBadge = updatedChannel.canShowBadge(); } if (!channel.equals(updatedChannel)) { // only log if there are real changes MetricsLogger.action(getChannelLog(updatedChannel, pkg)); } if (updatedChannel.canBypassDnd() != mAreChannelsBypassingDnd) { updateChannelsBypassingDnd(); } updateConfig(); }
Example 2
Source File: ShortcutNotificationManager.java From HayaiLauncher with Apache License 2.0 | 5 votes |
public static int getPriorityFromString(String priority) { int i_priority = 0; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (priority.toLowerCase().equals("max")) { i_priority = Notification.PRIORITY_MAX; } else if (priority.toLowerCase().equals("min")) { i_priority = Notification.PRIORITY_MIN; } } return i_priority; }
Example 3
Source File: NotificationHelper.java From react-native-foreground-service with MIT License | 4 votes |
Notification buildNotification(Context context, Bundle notificationConfig) { if (notificationConfig == null) { Log.e("NotificationHelper", "buildNotification: invalid config"); return null; } Class mainActivityClass = getMainActivityClass(context); if (mainActivityClass == null) { return null; } Intent notificationIntent = new Intent(context, mainActivityClass); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); Notification.Builder notificationBuilder; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { String channelId = notificationConfig.getString("channelId"); if (channelId == null) { Log.e("NotificationHelper", "buildNotification: invalid channelId"); return null; } notificationBuilder = new Notification.Builder(context, channelId); } else { notificationBuilder = new Notification.Builder(context); } int priorityInt = notificationConfig.containsKey("priority") ? notificationConfig.getInt("priority"): Notification.PRIORITY_HIGH; int priority; switch (priorityInt) { case 0: priority = Notification.PRIORITY_DEFAULT; break; case -1: priority = Notification.PRIORITY_LOW; break; case -2: priority = Notification.PRIORITY_MIN; break; case 1: priority = Notification.PRIORITY_HIGH; break; case 2: priority = Notification.PRIORITY_MAX; break; default: priority = Notification.PRIORITY_HIGH; break; } notificationBuilder.setContentTitle(notificationConfig.getString("title")) .setContentText(notificationConfig.getString("text")) .setPriority(priority) .setContentIntent(pendingIntent); String iconName = notificationConfig.getString("icon"); if (iconName != null) { notificationBuilder.setSmallIcon(getResourceIdForResourceName(context, iconName)); } return notificationBuilder.build(); }
Example 4
Source File: NotificationRecord.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
private int calculateImportance() { final Notification n = sbn.getNotification(); int importance = getChannel().getImportance(); int requestedImportance = IMPORTANCE_DEFAULT; // Migrate notification flags to scores if (0 != (n.flags & Notification.FLAG_HIGH_PRIORITY)) { n.priority = Notification.PRIORITY_MAX; } n.priority = NotificationManagerService.clamp(n.priority, Notification.PRIORITY_MIN, Notification.PRIORITY_MAX); switch (n.priority) { case Notification.PRIORITY_MIN: requestedImportance = IMPORTANCE_MIN; break; case Notification.PRIORITY_LOW: requestedImportance = IMPORTANCE_LOW; break; case Notification.PRIORITY_DEFAULT: requestedImportance = IMPORTANCE_DEFAULT; break; case Notification.PRIORITY_HIGH: case Notification.PRIORITY_MAX: requestedImportance = IMPORTANCE_HIGH; break; } stats.requestedImportance = requestedImportance; stats.isNoisy = mSound != null || mVibration != null; if (mPreChannelsNotification && (importance == IMPORTANCE_UNSPECIFIED || (getChannel().getUserLockedFields() & USER_LOCKED_IMPORTANCE) == 0)) { if (!stats.isNoisy && requestedImportance > IMPORTANCE_LOW) { requestedImportance = IMPORTANCE_LOW; } if (stats.isNoisy) { if (requestedImportance < IMPORTANCE_DEFAULT) { requestedImportance = IMPORTANCE_DEFAULT; } } if (n.fullScreenIntent != null) { requestedImportance = IMPORTANCE_HIGH; } importance = requestedImportance; } stats.naturalImportance = importance; return importance; }
Example 5
Source File: ZenModeFiltering.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
public boolean shouldIntercept(int zen, ZenModeConfig config, NotificationRecord record) { if (zen == ZEN_MODE_OFF) { return false; } // Make an exception to policy for the notification saying that policy has changed if (NotificationManager.Policy.areAllVisualEffectsSuppressed(config.suppressedVisualEffects) && "android".equals(record.sbn.getPackageName()) && SystemMessageProto.SystemMessage.NOTE_ZEN_UPGRADE == record.sbn.getId()) { ZenLog.traceNotIntercepted(record, "systemDndChangedNotification"); return false; } switch (zen) { case Global.ZEN_MODE_NO_INTERRUPTIONS: // #notevenalarms ZenLog.traceIntercepted(record, "none"); return true; case Global.ZEN_MODE_ALARMS: if (isAlarm(record)) { // Alarms only return false; } ZenLog.traceIntercepted(record, "alarmsOnly"); return true; case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS: // allow user-prioritized packages through in priority mode if (record.getPackagePriority() == Notification.PRIORITY_MAX) { ZenLog.traceNotIntercepted(record, "priorityApp"); return false; } if (isAlarm(record)) { if (!config.allowAlarms) { ZenLog.traceIntercepted(record, "!allowAlarms"); return true; } return false; } if (isCall(record)) { if (config.allowRepeatCallers && REPEAT_CALLERS.isRepeat(mContext, extras(record))) { ZenLog.traceNotIntercepted(record, "repeatCaller"); return false; } if (!config.allowCalls) { ZenLog.traceIntercepted(record, "!allowCalls"); return true; } return shouldInterceptAudience(config.allowCallsFrom, record); } if (isMessage(record)) { if (!config.allowMessages) { ZenLog.traceIntercepted(record, "!allowMessages"); return true; } return shouldInterceptAudience(config.allowMessagesFrom, record); } if (isEvent(record)) { if (!config.allowEvents) { ZenLog.traceIntercepted(record, "!allowEvents"); return true; } return false; } if (isReminder(record)) { if (!config.allowReminders) { ZenLog.traceIntercepted(record, "!allowReminders"); return true; } return false; } if (isMedia(record)) { if (!config.allowMedia) { ZenLog.traceIntercepted(record, "!allowMedia"); return true; } return false; } if (isSystem(record)) { if (!config.allowSystem) { ZenLog.traceIntercepted(record, "!allowSystem"); return true; } return false; } ZenLog.traceIntercepted(record, "!priority"); return true; default: return false; } }