Package org.robolectric.shadows
Class ShadowNotificationManager
java.lang.Object
org.robolectric.shadows.ShadowNotificationManager
@Implements(value=android.app.NotificationManager.class, looseSignatures=true) public class ShadowNotificationManager extends Object
-
Constructor Summary
Constructors Constructor Description ShadowNotificationManager()
-
Method Summary
Modifier and Type Method Description protected String
addAutomaticZenRule(AutomaticZenRule automaticZenRule)
protected boolean
areNotificationsEnabled()
protected void
cancel(int id)
protected void
cancel(String tag, int id)
protected void
cancelAll()
protected boolean
canNotifyAsPackage(String pkg)
protected void
createNotificationChannel(Object channel)
protected void
createNotificationChannelGroup(Object group)
protected void
createNotificationChannelGroups(List<Object> groupList)
protected void
createNotificationChannels(List<Object> channelList)
protected void
deleteNotificationChannel(String channelId)
protected void
deleteNotificationChannelGroup(String channelGroupId)
Delete a notification channel group and all notification channels associated with the group.StatusBarNotification[]
getActiveNotifications()
List<Notification>
getAllNotifications()
protected AutomaticZenRule
getAutomaticZenRule(String id)
protected Map<String,AutomaticZenRule>
getAutomaticZenRules()
protected int
getCurrentInterruptionFilter()
protected int
getImportance()
Notification
getNotification(int id)
Notification
getNotification(String tag, int id)
protected Object
getNotificationChannel(String channelId)
protected NotificationChannel
getNotificationChannel(String channelId, String conversationId)
Returns a NotificationChannel that has the given parent and conversation ID.Object
getNotificationChannelGroup(String id)
protected List<Object>
getNotificationChannelGroups()
List<Object>
getNotificationChannels()
protected String
getNotificationDelegate()
protected NotificationManager.Policy
getNotificationPolicy()
boolean
isChannelDeleted(String channelId)
Checks whether a channel is considered a "deleted" channel by Android.protected boolean
isNotificationListenerAccessGranted(ComponentName componentName)
protected boolean
isNotificationPolicyAccessGranted()
protected void
notify(int id, Notification notification)
protected void
notify(String tag, int id, Notification notification)
protected boolean
removeAutomaticZenRule(String id)
void
setCanNotifyAsPackage(String otherPackage, boolean canNotify)
Sets notification delegate for the package provided.void
setEnforceMaxNotificationLimit(boolean enforceMaxNotificationLimit)
Ensures a notification limit is applied before posting the notification.void
setImportance(int importance)
protected void
setInterruptionFilter(int interruptionFilter)
Currently does not support checking for granted policy access.protected void
setNotificationDelegate(String delegate)
void
setNotificationListenerAccessGranted(ComponentName componentName, boolean granted)
Sets the value returned byNotificationManager.isNotificationListenerAccessGranted(ComponentName)
for the providedComponentName
.protected void
setNotificationPolicy(NotificationManager.Policy policy)
Currently does not support checking for granted policy access.void
setNotificationPolicyAccessGranted(boolean granted)
Sets the value returned byNotificationManager.isNotificationPolicyAccessGranted()
.void
setNotificationsEnabled(boolean areNotificationsEnabled)
int
size()
protected boolean
updateAutomaticZenRule(String id, AutomaticZenRule automaticZenRule)
-
Constructor Details
-
ShadowNotificationManager
public ShadowNotificationManager()
-
-
Method Details
-
notify
-
notify
-
cancel
-
cancel
-
cancelAll
-
areNotificationsEnabled
-
setNotificationsEnabled
public void setNotificationsEnabled(boolean areNotificationsEnabled) -
getImportance
-
setImportance
public void setImportance(int importance) -
getActiveNotifications
-
getNotificationChannel
-
getNotificationChannel
@Implementation(minSdk=30) protected NotificationChannel getNotificationChannel(String channelId, String conversationId)Returns a NotificationChannel that has the given parent and conversation ID. -
createNotificationChannelGroup
-
createNotificationChannelGroups
-
getNotificationChannelGroups
-
createNotificationChannel
-
createNotificationChannels
-
getNotificationChannels
-
deleteNotificationChannel
-
deleteNotificationChannelGroup
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
- Returns:
NotificationManager.INTERRUPTION_FILTER_ALL
by default, or the value specified viasetInterruptionFilter(int)
-
setInterruptionFilter
Currently does not support checking for granted policy access. -
getNotificationPolicy
- Returns:
- the value specified via
setNotificationPolicy(Policy)
-
isNotificationPolicyAccessGranted
- Returns:
- the value specified via
setNotificationPolicyAccessGranted(boolean)
-
isNotificationListenerAccessGranted
@Implementation(minSdk=27) protected final boolean isNotificationListenerAccessGranted(ComponentName componentName)- Returns:
- the value specified for the given
ComponentName
viasetNotificationListenerAccessGranted(ComponentName, boolean)
or false if unset.
-
setNotificationPolicy
@Implementation(minSdk=23) protected final void setNotificationPolicy(NotificationManager.Policy policy)Currently does not support checking for granted policy access. -
setNotificationPolicyAccessGranted
public void setNotificationPolicyAccessGranted(boolean granted)Sets the value returned byNotificationManager.isNotificationPolicyAccessGranted()
. Ifgranted
is false, this also deletes allAutomaticZenRule
s. -
setNotificationListenerAccessGranted
Sets the value returned byNotificationManager.isNotificationListenerAccessGranted(ComponentName)
for the providedComponentName
. -
getAutomaticZenRule
-
getAutomaticZenRules
-
addAutomaticZenRule
-
updateAutomaticZenRule
@Implementation(minSdk=24) protected boolean updateAutomaticZenRule(String id, AutomaticZenRule automaticZenRule) -
removeAutomaticZenRule
-
getNotificationDelegate
-
canNotifyAsPackage
-
setCanNotifyAsPackage
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 behalfcanNotify
- whether the current package is set as notification delegate for 'otherPackage'
-
setNotificationDelegate
-
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
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
-
size
public int size() -
getNotification
-
getNotification
-
getAllNotifications
-