我试图在单击菜单项时显示通知消息,它向我显示了指示器,但我没有看到该消息,有人可以解释我哪里做错了吗:
private MenuItem AMenu = new MenuItem("Notify", 101, 10)
{
public void run()
{
ReadableListImpl mylist= new ReadableListImpl();
ApplicationMessageFolder folder = null;
if(ApplicationMessageFolderRegistry.getInstance().getApplicationFolder(0x33c7ce29883abe5fL)==null){
folder = ApplicationMessageFolderRegistry.getInstance().registerFolder(
0x33c7ce29883abe5fL, "Test Folder", mylist );
}else {
folder = ApplicationMessageFolderRegistry.getInstance().getApplicationFolder(0x33c7ce29883abe5fL);
}
//DemoMessage source is available in the messagelistdemo.
DemoMessage msg = new DemoMessage("me@here.com", "Pizza Toppings","What would you like on your pizza?", System.currentTimeMillis());
mylist.addMessage(msg);
folder.fireElementAdded(msg,true);
System.out.println("nr of messages"+folder.hasNewMessages());
ApplicationIndicatorRegistry reg =
ApplicationIndicatorRegistry.getInstance();
EncodedImage image = EncodedImage.getEncodedImageResource("new.png" );
ApplicationIcon icon = new ApplicationIcon( image );
ApplicationIndicator indicator = reg.register( icon, false, true);
ApplicationIndicator appIndicator = reg.getApplicationIndicator();
appIndicator.setIcon(icon);
appIndicator.setValue(appIndicator.getValue() + 1);
appIndicator.setNotificationState(true);
appIndicator.setVisible(true);;
}
};
最佳答案
查看您的代码时我注意到两件事:
首先,每次调用菜单项时都会创建一个新的 ReadableListImpl。这意味着您添加消息的 ReadableListImpl 实例并不总是与注册文件夹时使用的实例相同。因此,您的代码应该在第一次调用时有效,但在后续调用中无效。
其次,在 BB OS 6 中,消息可以出现在两个位置:主屏幕(通知栏)和消息列表(“消息”应用程序)。您的消息可能确实显示在消息列表中,但没有显示在通知栏中。根据我的经验,仅当消息的状态为 ApplicationMessage.Status.UNOPENED 时,消息才会显示在通知栏中。
如果您想控制消息的显示位置,请使用 ApplicationFolderIntegrationConfig。
关于java - 黑莓通知消息问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5596507/