问题
I am trying to make a notification message appear when I click the menu item, it shows me the indicator but I don't see the message, can someone explain where i did wrong :
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);;
}
};
回答1:
I noticed two things looking at your code:
First, you create a new ReadableListImpl each time the menu item gets invoked. This means the ReadableListImpl instance you add the message to is not always the same as the one that was used when registering the folder. So your code should work on first invocation but not on subsequent ones.
Second, with BB OS 6 a message can appear in two places, the home screen (notification bar) and the message list (the 'Messages' app). It might be possible that your message did actually show up in the message list but not in the notification bar. From my experience messages show up in the notification bar only if the message's status is ApplicationMessage.Status.UNOPENED.
Use ApplicationFolderIntegrationConfig if you want to have control over where your message should show up.
来源:https://stackoverflow.com/questions/5596507/blackberry-notification-message-issue