黑莓-“您目前没有新的通知" [英] Blackberry - "you currently have no new notifications"

查看:71
本文介绍了黑莓-“您目前没有新的通知"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用下面的代码(尤其是 pushMessage 方法)向用户显示一些通知:

I'm using the code below (especially pushMessage method) to show some notification to user:

public final class MyApplicationMessageFolder 
{
    public static final long MyFolderId = 0x1256789012F10123L;

    private ApplicationMessageFolder folder_;
    private ApplicationIndicator indicator_;
    private MyReadableListImpl collection_;

    public void pushMessage(String subject, String message)
    {
        try 
        {
            if (collection_ == null)
            {
                collection_ = new MyReadableListImpl();
            }
            if (indicator_ == null)
            {
                registerFolderAndIndicator();
            }

            ApplicationMessage am = new MyApplicationMessage(message, subject);
            collection_.addMessage(am);
            folder_.fireElementAdded(am);

            // Update indicator
            int size = collection_.size();
            indicator_.setValue(size);
            indicator_.setVisible(size > 0);
        } 
        catch (Exception e)
        {
            System.out.println(e.getMessage());
        }
    }

    private void registerFolderAndIndicator()
    {
        // registration application folder and indicator
        ApplicationMessageFolderRegistry amfr = 
                ApplicationMessageFolderRegistry.getInstance();
        folder_ = amfr.getApplicationFolder(MyFolderId );

        if (folder_ == null)
        {
            folder_ = 
                    amfr.registerFolder(MyFolderId , "My Folder", collection_, true);
            ApplicationIcon icon = 
                    new ApplicationIcon(image_ = EncodedImage.getEncodedImageResource("my_icon.png"), true);
            int status = ApplicationMessage.Status.INCOMING | ApplicationMessage.Status.UNOPENED;

            amfr.registerMessageIcon(0, status, icon);
            folder_.setSearchProperties(new ApplicationMessageSearchProperties(true));
            folder_.addListener(
                    new ApplicationMessageFolderListener() {

                        public void actionPerformed(int action, ApplicationMessage[] messages,
                                ApplicationMessageFolder folder) {
                            if (action == ApplicationMessageFolderListener.MESSAGE_DELETED) {
                                for (int i = 0; i < messages.length; i++)
                                    collection_.removeMessage(messages[i]);

                                indicator_.setValue(collection_.size());
                                indicator_.setVisible(collection_.size() > 0);
                            }
                        }
                    },
                    ApplicationMessageFolderListener.MESSAGE_DELETED | 
                            ApplicationMessageFolderListener.MESSAGE_MARKED_OPENED | 
                            ApplicationMessageFolderListener.MESSAGE_MARKED_UNOPENED, 
                    ApplicationDescriptor.currentApplicationDescriptor());

            ApplicationMenuItem[] menu = new ApplicationMenuItem[] {

                    new ApplicationMenuItem(0) {

                        public String toString() {
                            return "Go to application";
                        }

                        public Object run(Object context) {
                            return null;
                        }
                    }
            };

            amfr.registerMessageMenuItems(0, status, menu, 
                    ApplicationDescriptor.currentApplicationDescriptor());
            amfr.setBulkMarkOperationsSupport(0, status, true, false);

            ApplicationIndicatorRegistry air = ApplicationIndicatorRegistry.getInstance();
            air.register(new ApplicationIcon(EncodedImage
                    .getEncodedImageResource("bar_icon_25.png")),
                    false, false);

            indicator_ = air.getApplicationIndicator();
        }
    }

    class MyApplicationMessage implements ApplicationMessage 
    {
        private String message_;
        private String subject_;
        private long timestamp_;

        public MyApplicationMessage(String message, String subject) {
            message_ = message;
            subject_ = subject;
            timestamp_ = new Date().getTime();
        }

        public String getContact() {
            return "HelloWorld";
        }

        public Object getCookie(int cookieId) {
            return null;
        }

        public Object getPreviewPicture() {
            return image_;
        }

        public String getPreviewText() {
            return message_;
        }

        public int getStatus() {
            return ApplicationMessage.Status.UNOPENED;
        }

        public String getSubject() {
            return subject_;
        }

        public long getTimestamp() {
            return timestamp_;
        }

        public int getType() {
            return 0x01;
        }
    }

    private class MyReadableListImpl implements ReadableList {
        private final Vector messages;


        MyReadableListImpl() {
            messages = new Vector();
        }

        public Object getAt(final int index) {
            return messages.elementAt(index);
        }

        public int getAt(final int index, final int count,
                final Object[] elements, final int destIndex) {
            return 0;
        }

        public int getIndex(final Object element) {
            return messages.indexOf(element);
        }

        public int size() {
            return messages.size();
        }

        void addMessage(final ApplicationMessage message) {
            messages.addElement(message);
        }

        void removeMessage(final ApplicationMessage message) {
            messages.removeElement(message);
        }
    }
}

我可以在我的消息文件夹中看到我的消息,但是在通知栏中仍然看不到它们

I can see my messages in my Message folder, But I still can't see them in notification bar

任何人都可以解释为什么我看到空白的通知栏吗?

Can anyone explain why I see empty notification bar?

谢谢

推荐答案

要查看通知下拉列表中的消息,则需要改用:

To see messges in notification drop-down list there is need use instead:

ApplicationFolderIntegrationConfig config = new 
        ApplicationFolderIntegrationConfig(true, true, 
        ApplicationDescriptor.currentApplicationDescriptor());
folder_ = amfr.registerFolder(MyFolderId , "My Folder", collection_, config);

相反:

folder_ = amfr.registerFolder(MyFolderId , "My Folder", collection_, true);

这篇关于黑莓-“您目前没有新的通知"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆