Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
colombus
Posts: 264
Registered: ‎06-04-2009
My Device: Not Specified

BlackBerry push message is not changing the state to read

Dear all,

 

I am developing an application which has push notifications. The problem is when the push notification message appears on my notification bar & when I click on the message from notification bar the application is opened but the message is not getting unread. The icon & count is still displayed at the top. I have to go to the inbox and delete the message manually. I am following the demo given in the JDE. But after I integrate it with the app and when actual push notification comes the notification message is not dispappearing,. Any idea on the above problem.

The below code snippet is not getting executed.

 

    /**
     * Open Context menu item. Marks read and opens the selected message for
     * viewing.
     */
    static class OpenContextMenu extends ApplicationMenuItem
    {
        /**
         * Creates a new ApplicationMenuItem instance with provided menu position
         * 
         * @param order Display order of this item, lower numbers correspond to higher placement in the menu
         */
        public OpenContextMenu(int order)
        {
            super(order);

            // Set icon for GCM menu
            EncodedImage eiOpen = EncodedImage.getEncodedImageResource("img/sm_open.png");
            if(eiOpen != null)
            {
                Image image = ImageFactory.createImage(eiOpen);
                this.setIcon(image);
            }
        }


        /**
         * @see ApplicationMenuItem#run(Object)
         */
        public Object run(Object context)
        {
            if(context instanceof DemoMessage)
            {
                DemoMessage message = (DemoMessage) context;

                // Update status if message is new
                if(message.isNew())
                {
                    message.markRead();
                    ApplicationMessageFolderRegistry reg = ApplicationMessageFolderRegistry.getInstance();
                    ApplicationMessageFolder folder = reg.getApplicationFolder(INBOX_FOLDER_ID);
                    folder.fireElementUpdated(message, message);
                    changeIndicator(-1);
                }

                // Show message
               // DemoMessageScreen previewScreen = new DemoMessageScreen(message);
                UiApplication uiApplication = UiApplication.getUiApplication();
               // uiApplication.pushScreen(previewScreen);*/
                uiApplication.requestForeground();
            }
            return context;
        }


        /**
         * @see java.lang.Object#toString()
         */
        public String toString()
        {
            return "View Demo Message";
        }
    }

 

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: BlackBerry push message is not changing the state to read

can you post the code where you register the menu item?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
colombus
Posts: 264
Registered: ‎06-04-2009
My Device: Not Specified

Re: BlackBerry push message is not changing the state to read

  void init() {
        // 1. Register folders and application descriptors
        // ----------------------

        final ApplicationMessageFolderRegistry reg =
                ApplicationMessageFolderRegistry.getInstance();

        // Some context menu items don't need a GUI (e.g. an item for deleting a
        // message) and will be run in the current daemon application.
        final ApplicationDescriptor daemonDescr =
                ApplicationDescriptor.currentApplicationDescriptor();

        // Main application descriptor - causes application to be launched with
        // default welcome screen if a user clicks on the "Message List Demo"
        // header in the home screen notifications view.
        final ApplicationDescriptor mainDescr =
                new ApplicationDescriptor(daemonDescr, APPLICATION_NAME,
                        new String[] {});

        // This application descriptor launches this application with a GUI to
        // execute listener callbacks, e.g. to display a message.
        final ApplicationDescriptor uiCallbackDescr =
                new ApplicationDescriptor(daemonDescr, APPLICATION_NAME,
                        new String[] { "gui" });

        // Get existing messages from storage and register them in folders
        final ApplicationFolderIntegrationConfig inboxIntegration =
                new ApplicationFolderIntegrationConfig(true, true, mainDescr);
        final ApplicationFolderIntegrationConfig deletedIntegration =
                new ApplicationFolderIntegrationConfig(false);

        final MessageListDemoStore messages =
                MessageListDemoStore.getInstance();
        final ApplicationMessageFolder inbox =
                reg.registerFolder(MessageListDemo.INBOX_FOLDER_ID, "Inbox",
                        messages.getInboxMessages(), inboxIntegration);
        final ApplicationMessageFolder deleted =
                reg.registerFolder(MessageListDemo.DELETED_FOLDER_ID,
                        "Deleted Messages", messages.getDeletedMessages(),
                        deletedIntegration);

        // Register as a listener for callback notifications
        inbox.addListener(
                this,
                ApplicationMessageFolderListener.MESSAGE_DELETED
                        | ApplicationMessageFolderListener.MESSAGE_MARKED_OPENED
                        | ApplicationMessageFolderListener.MESSAGE_MARKED_UNOPENED
                        | ApplicationMessageFolderListener.MESSAGES_MARKED_OLD,
                daemonDescr);
        deleted.addListener(this,
                ApplicationMessageFolderListener.MESSAGE_DELETED, daemonDescr);

        messages.setFolders(inbox, deleted);

        // We've registered two folders, specify root folder name for the
        // [View Folder] screen.
        reg.setRootFolderName(APPLICATION_NAME);

        // 2. Register message icons -------------------------------------------

        final ApplicationIcon newIcon =
                new ApplicationIcon(EncodedImage
                        .getEncodedImageResource("img/new.png"));
        final ApplicationIcon readIcon =
                new ApplicationIcon(EncodedImage
                        .getEncodedImageResource("img/read.png"));
        final ApplicationIcon repliedIcon =
                new ApplicationIcon(EncodedImage
                        .getEncodedImageResource("img/replied.png"));
        final ApplicationIcon deletedIcon =
                new ApplicationIcon(EncodedImage
                        .getEncodedImageResource("img/deleted.png"));

        reg.registerMessageIcon(DemoMessage.DEMO_MESSAGE_TYPE,
                MessageListDemo.STATUS_NEW, newIcon);
        reg.registerMessageIcon(DemoMessage.DEMO_MESSAGE_TYPE,
                MessageListDemo.STATUS_OPENED, readIcon);
        reg.registerMessageIcon(DemoMessage.DEMO_MESSAGE_TYPE,
                MessageListDemo.STATUS_REPLIED, repliedIcon);
        reg.registerMessageIcon(DemoMessage.DEMO_MESSAGE_TYPE,
                MessageListDemo.STATUS_DELETED, deletedIcon);

        // 3. Register message menu items --------------------------------------

        final ApplicationMenuItem openMenuItem = new OpenContextMenu(0x230010);
        final ApplicationMenuItem replyMenuItem =
                new ReplyContextMenu(0x230020);
        final ApplicationMenuItem markOpenedMenuItem =
                new MarkOpenedContextMenu(0x230030);
        final ApplicationMenuItem markUnopenedMenuItem =
                new MarkUnreadContextMenu(0x230040);

        final ApplicationMenuItem[] newGuiMenuItems =
                new ApplicationMenuItem[] { openMenuItem };
        final ApplicationMenuItem[] newDaemonMenuItems =
                new ApplicationMenuItem[] { markOpenedMenuItem, replyMenuItem };
        final ApplicationMenuItem[] openedGuiMenuItems =
                new ApplicationMenuItem[] { openMenuItem };
        final ApplicationMenuItem[] openedDaemonMenuItems =
                new ApplicationMenuItem[] { markUnopenedMenuItem, replyMenuItem };
        final ApplicationMenuItem[] repliedGuiMenuItems =
                new ApplicationMenuItem[] { openMenuItem };
        final ApplicationMenuItem[] repliedDaemonMenuItems =
                new ApplicationMenuItem[] { markUnopenedMenuItem };
        final ApplicationMenuItem[] deletedGuiMenuItems =
                new ApplicationMenuItem[] { openMenuItem, };

        reg.registerMessageMenuItems(DemoMessage.DEMO_MESSAGE_TYPE,
                MessageListDemo.STATUS_NEW, newGuiMenuItems, uiCallbackDescr);
        reg.registerMessageMenuItems(DemoMessage.DEMO_MESSAGE_TYPE,
                MessageListDemo.STATUS_NEW, newDaemonMenuItems, daemonDescr);
        reg.registerMessageMenuItems(DemoMessage.DEMO_MESSAGE_TYPE,
                MessageListDemo.STATUS_OPENED, openedGuiMenuItems,
                uiCallbackDescr);
        reg.registerMessageMenuItems(DemoMessage.DEMO_MESSAGE_TYPE,
                MessageListDemo.STATUS_OPENED, openedDaemonMenuItems,
                daemonDescr);
        reg.registerMessageMenuItems(DemoMessage.DEMO_MESSAGE_TYPE,
                MessageListDemo.STATUS_REPLIED, repliedGuiMenuItems,
                uiCallbackDescr);
        reg.registerMessageMenuItems(DemoMessage.DEMO_MESSAGE_TYPE,
                MessageListDemo.STATUS_REPLIED, repliedDaemonMenuItems,
                daemonDescr);
        reg.registerMessageMenuItems(DemoMessage.DEMO_MESSAGE_TYPE,
                MessageListDemo.STATUS_DELETED, deletedGuiMenuItems,
                uiCallbackDescr);

        reg.setBulkMarkOperationsSupport(DemoMessage.DEMO_MESSAGE_TYPE,
                MessageListDemo.STATUS_NEW, true, false);
        reg.setBulkMarkOperationsSupport(DemoMessage.DEMO_MESSAGE_TYPE,
                MessageListDemo.STATUS_OPENED, false, true);
        reg.setBulkMarkOperationsSupport(DemoMessage.DEMO_MESSAGE_TYPE,
                MessageListDemo.STATUS_REPLIED, false, true);
    }

  same as example I am changing the folder address & keys given in demo