Class ShadowNotificationManager

java.lang.Object
org.robolectric.shadows.ShadowNotificationManager

@Implements(android.app.NotificationManager.class) public class ShadowNotificationManager extends Object
Shadows for NotificationManager.
  • Constructor Details

    • ShadowNotificationManager

      public ShadowNotificationManager()
  • Method Details

    • reset

      @Resetter public static void reset()
    • notify

      @Implementation protected void notify(int id, Notification notification)
    • notify

      @Implementation protected void notify(String tag, int id, Notification notification)
    • cancel

      @Implementation protected void cancel(int id)
    • cancel

      @Implementation protected void cancel(String tag, int id)
    • cancelAll

      @Implementation protected void cancelAll()
    • areNotificationsEnabled

      @Implementation(minSdk=24) protected boolean areNotificationsEnabled()
    • setNotificationsEnabled

      public void setNotificationsEnabled(boolean areNotificationsEnabled)
    • getImportance

      @Implementation(minSdk=24) protected int getImportance()
    • setImportance

      public void setImportance(int importance)
    • getActiveNotifications

      @Implementation(minSdk=23) public StatusBarNotification[] getActiveNotifications()
    • getNotificationChannel

      @Implementation(minSdk=26) protected NotificationChannel getNotificationChannel(String channelId)
    • getNotificationChannel

      @Implementation(minSdk=30) protected NotificationChannel getNotificationChannel(String channelId, String conversationId)
      Returns a NotificationChannel that has the given parent and conversation ID.
    • createNotificationChannelGroup

      @Implementation(minSdk=26) protected void createNotificationChannelGroup(NotificationChannelGroup group)
    • createNotificationChannelGroups

      @Implementation(minSdk=26) protected void createNotificationChannelGroups(List<NotificationChannelGroup> groupList)
    • getNotificationChannelGroups

      @Implementation(minSdk=26) protected List<NotificationChannelGroup> getNotificationChannelGroups()
    • createNotificationChannel

      @Implementation(minSdk=26) protected void createNotificationChannel(NotificationChannel channel)
    • createNotificationChannels

      @Implementation(minSdk=26) protected void createNotificationChannels(List<NotificationChannel> channelList)
    • getNotificationChannels

      @Implementation(minSdk=26) public List<NotificationChannel> getNotificationChannels()
    • deleteNotificationChannel

      @Implementation(minSdk=26) protected void deleteNotificationChannel(String channelId)
    • deleteNotificationChannelGroup

      @Implementation(minSdk=26) protected void deleteNotificationChannelGroup(String channelGroupId)
      Delete a notification channel group and all notification channels associated with the group. This method will not notify any NotificationListenerService of resulting changes to notification channel groups nor to notification channels.
    • getCurrentInterruptionFilter

      @Implementation(minSdk=23) protected int getCurrentInterruptionFilter()
      Returns:
      NotificationManager.INTERRUPTION_FILTER_ALL by default, or the value specified via setInterruptionFilter(int)
    • setInterruptionFilter

      @Implementation(minSdk=23) protected void setInterruptionFilter(int interruptionFilter)
      Currently does not support checking for granted policy access.
      See Also:
    • getNotificationPolicy

      @Implementation(minSdk=23) protected NotificationManager.Policy getNotificationPolicy()
      Returns:
      the value specified via setNotificationPolicy(Policy)
    • setConsolidatedNotificationPolicy

      public void setConsolidatedNotificationPolicy(NotificationManager.Policy policy)
      Specifies the consolidated notification policy to return
      See Also:
    • getConsolidatedNotificationPolicy

      @Implementation(minSdk=30) protected NotificationManager.Policy getConsolidatedNotificationPolicy()
      Returns:
      the value specified via setConsolidatedNotificationPolicy(Policy)
    • isNotificationPolicyAccessGranted

      @Implementation(minSdk=23) protected boolean isNotificationPolicyAccessGranted()
      Returns:
      the value specified via setNotificationPolicyAccessGranted(boolean)
    • isNotificationListenerAccessGranted

      @Implementation(minSdk=27) protected boolean isNotificationListenerAccessGranted(ComponentName componentName)
      Returns:
      the value specified for the given ComponentName via setNotificationListenerAccessGranted(ComponentName, boolean) or false if unset.
    • setNotificationPolicy

      @Implementation(minSdk=23) protected void setNotificationPolicy(NotificationManager.Policy policy)
      Currently does not support checking for granted policy access.
      See Also:
    • setNotificationPolicyAccessGranted

      public void setNotificationPolicyAccessGranted(boolean granted)
      Sets the value returned by NotificationManager.isNotificationPolicyAccessGranted(). If granted is false, this also deletes all AutomaticZenRules.
      See Also:
    • setNotificationListenerAccessGranted

      @Implementation(minSdk=27) public void setNotificationListenerAccessGranted(ComponentName componentName, boolean granted)
    • getAutomaticZenRule

      @Implementation(minSdk=24) protected AutomaticZenRule getAutomaticZenRule(String id)
    • getAutomaticZenRules

      @Implementation(minSdk=24) protected Map<String,AutomaticZenRule> getAutomaticZenRules()
    • addAutomaticZenRule

      @Implementation(minSdk=24) protected String addAutomaticZenRule(AutomaticZenRule automaticZenRule)
    • updateAutomaticZenRule

      @Implementation(minSdk=24) protected boolean updateAutomaticZenRule(String id, AutomaticZenRule automaticZenRule)
    • removeAutomaticZenRule

      @Implementation(minSdk=24) protected boolean removeAutomaticZenRule(String id)
    • getNotificationDelegate

      @Implementation(minSdk=29) protected String getNotificationDelegate()
    • canNotifyAsPackage

      @Implementation(minSdk=29) protected boolean canNotifyAsPackage(@Nonnull String pkg)
    • setCanNotifyAsPackage

      public void setCanNotifyAsPackage(@Nonnull String otherPackage, boolean canNotify)
      Sets notification delegate for the package provided.

      canNotifyAsPackage(String) will be returned based on this value.

      Parameters:
      otherPackage - the package for which the current package can notify on behalf
      canNotify - whether the current package is set as notification delegate for 'otherPackage'
    • setNotificationDelegate

      @Implementation(minSdk=29) protected void setNotificationDelegate(String delegate)
    • setEnforceMaxNotificationLimit

      public void setEnforceMaxNotificationLimit(boolean enforceMaxNotificationLimit)
      Ensures a notification limit is applied before posting the notification.

      When set to true a maximum notification limit of 25 is applied. Notifications past this limit are dropped and are not posted or enqueued.

      When set to false no limit is applied and all notifications are posted or enqueued. This is the default behavior.

    • isChannelDeleted

      public boolean isChannelDeleted(String channelId)
      Checks whether a channel is considered a "deleted" channel by Android. This is a channel that was created but later deleted. If a channel is created that was deleted before, it recreates the channel with the old settings.
    • getNotificationChannelGroup

      @Implementation(minSdk=28) public NotificationChannelGroup getNotificationChannelGroup(String id)
    • size

      public int size()
    • getNotification

      public Notification getNotification(int id)
    • getNotification

      public Notification getNotification(String tag, int id)
    • getAllNotifications

      public List<Notification> getAllNotifications()