public class NotificationFilterSupport extends Object implements NotificationFilter
NotificationFilter 接口的实现。
对通知类型属性执行过滤。
管理已启用通知类型的列表。 一种方法允许用户根据需要启用/禁用尽可能多的通知类型。
然后,在向过滤器注册的收听者发送通知之前,通知广播者将该通知类型与由过滤器启用的所有通知类型进行比较。 只有当该过滤器启用此通知类型时,该通知才会发送给侦听器。
例:
NotificationFilterSupport myFilter = new NotificationFilterSupport();
myFilter.enableType("my_example.my_type");
myBroadcaster.addListener(myListener, myFilter, null);
侦听器myListener将仅接收类型为“my_example.my_type”的类型的通知。
| Constructor and Description |
|---|
NotificationFilterSupport() |
| Modifier and Type | Method and Description |
|---|---|
void |
disableAllTypes()
禁用所有通知类型。
|
void |
disableType(String prefix)
从前缀列表中删除给定的前缀。
|
void |
enableType(String prefix)
启用所有类型的通知以指定的前缀开始发送到侦听器。
|
Vector<String> |
getEnabledTypes()
获取此过滤器的所有启用的通知类型。
|
boolean |
isNotificationEnabled(Notification notification)
在将指定的通知发送给侦听器之前调用。
|
public boolean isNotificationEnabled(Notification notification)
true 。
isNotificationEnabled在接口
NotificationFilter
notification - 要发送的通知。
true如果通知应该发送给侦听器,
false false。
public void enableType(String prefix) throws IllegalArgumentException
例:
// Enables all notifications the type of which starts with "my_example" to be sent.
myFilter.enableType("my_example");
// Enables all notifications the type of which is "my_example.my_type" to be sent.
myFilter.enableType("my_example.my_type");
注意:
myFilter.enableType("my_example.*");
将不会匹配任何通知类型。
prefix - 前缀。
IllegalArgumentException - 前缀参数为空。
public void disableType(String prefix)
prefix - 前缀。
public void disableAllTypes()
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.