当从应用程序消息文件夹打开消息时,我希望有一个侦听器。为此,我使用了 ApplicationMenuItem,但在注册后,该消息无法再打开。
ApplicationMessageFolderRegistry messagefolderRegistry = ApplicationMessageFolderRegistry.getInstance();
messaageMenuItemListener = new CVSMessaageMenuItemListener();
CVSApplicationMenuItem menuItem = new CVSApplicationMenuItem();
menuItem.registerMenuItemListener(messaageMenuItemListener);
messagefolderRegistry.registerMessageMenuItems(CVSApplicationMessage.TYPE_ALARMS, ApplicationMessage.Status.UNOPENED, new ApplicationMenuItem[]{menuItem});
messagefolderRegistry.registerMessageIcon(CVSApplicationMessage.TYPE_ALARMS, ApplicationMessage.Status.UNOPENED, alarmsIcon);
和菜单项:
public class CVSApplicationMenuItem extends ApplicationMenuItem {
private CVSVector listeners;
CVSApplicationMenuItem(){
super(20);
}
public Object run(Object context) {
if(!(context instanceof CVSApplicationMessage))
return context;
CVSApplicationMessage applicationMessage = (CVSApplicationMessage)context;
if(listeners == null)
return context;
for (int i = 0; i < listeners.size(); i++) {
((ICVSApplicationMessageMenuItemListener)listeners.itemAt(i)).messageReaded(applicationMessage);
}
return context;
}
public void registerMenuItemListener(ICVSApplicationMessageMenuItemListener l){
if(listeners == null)
listeners = new CVSVector();
if(l != null)
listeners.addItem(l);
}
public String toString() {
return null;
}
}
我可以在消息列表中看到消息(从主页通知图标打开),但无法打开它。如果我执行以下操作,它会起作用,但是当它打开消息时我没有回调:
//messagefolderRegistry.registerMessageMenuItems(CVSApplicationMessage.TYPE_ALARMS, ApplicationMessage.Status.UNOPENED, new ApplicationMenuItem[]{menuItem});