黑莓 - “您目前没有新通知”

2024-02-03

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

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);
        }
    }
}

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

谁能解释一下为什么我看到空的通知栏?

Thanks


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

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

instead:

folder_ = amfr.registerFolder(MyFolderId , "My Folder", collection_, true);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

黑莓 - “您目前没有新通知” 的相关文章

  • 如何将 Java 赋值表达式转换为 Kotlin

    java中的一些东西就像 int a 1 b 2 c 1 if a b c System out print true 现在它应该转换为 kotlin 就像 var a Int 1 var b Int 2 var c Int 1 if a
  • 如何在 JFace 的 TableViewer 中创建复选框?

    我创建了一个包含两列的 tableViewer 我想将其中一列设为复选框 为此 我创建了一个 CheckBoxCellEditor 但我不知道为什么它不起作用 名为 tableName 的列显示其值正常 色谱柱规格如下 String COL
  • AES 加密 Java/plsql

    我需要在Java和plsql DBMS CRYPTO for Oracle 10g 上实现相同的加密 解密应用程序 两种实现都工作正常 但这里的问题是我对相同纯文本的加密得到了不同的输出 下面是用于加密 解密过程的代码 Java 和 PLS
  • 解决错误:日志已在具有多个实例的atomikos中使用

    我仅在使用atomikos的实时服务器上遇到问题 在我的本地服务器上它工作得很好 我在服务器上面临的问题是 init 中出错 日志已在使用中 完整的异常堆栈跟踪 java lang RuntimeException Log already
  • java.io.IOException: %1 不是有效的 Win32 应用程序

    我正在尝试对 XML 文档进行数字签名 为此我有两个选择 有一个由爱沙尼亚认证中心为程序员创建的库 还有一个由银行制作的运行 Java 代码的脚本 如果使用官方 认证中心 库 那么一切都会像魅力一样进行一些调整 但是当涉及到银行脚本时 它会
  • 如何在 Java 中禁用 System.out 以提高速度

    我正在用 Java 编写一个模拟重力的程序 其中有一堆日志语句 到 System out 我的程序运行速度非常慢 我认为日志记录可能是部分原因 有什么方法可以禁用 System out 以便我的程序在打印时不会变慢 或者我是否必须手动检查并
  • 如何为 Gson 编写自定义 JSON 反序列化器?

    我有一个 Java 类 用户 public class User int id String name Timestamp updateDate 我收到一个包含来自 Web 服务的用户对象的 JSON 列表 id 1 name Jonas
  • jdbc4.MySQLSyntaxErrorException:数据库中不存在表

    我正在使用 SpringBoot 开发一个网络应用程序 这是我的application properties文件来指定访问数据库的凭据 spring datasource driverClassName com mysql jdbc Dri
  • 使用替换字符串中多个单词的最有效方法[重复]

    这个问题在这里已经有答案了 此刻我正在做 Example line replaceAll replaceAll cat dog replaceAll football rugby 我觉得那很丑 不确定有更好的方法吗 也许循环遍历哈希图 ED
  • 迁移到 java 17 后有关“每个进程的内存映射”和 JVM 崩溃的 GC 警告

    我们正在将 java 8 应用程序迁移到 java 17 并将 GC 从G1GC to ZGC 我们的应用程序作为容器运行 这两个基础映像之间的唯一区别是 java 的版本 例如对于 java 17 版本 FROM ubuntu 20 04
  • 序列化对象以进行单元测试

    假设在单元测试中我需要一个对象 其中所有 50 个字段都设置了一些值 我不想手动设置所有这些字段 因为这需要时间而且很烦人 不知何故 我需要获得一个实例 其中所有字段都由一些非空值初始化 我有一个想法 如果我要调试一些代码 在某个时候我会得
  • 检查 protobuf 消息 - 如何按名称获取字段值?

    我似乎无法找到一种方法来验证 protobuf 消息中字段的值 而无需显式调用其 getter 我看到周围的例子使用Descriptors FieldDescriptor实例到达消息映射内部 但它们要么基于迭代器 要么由字段号驱动 一旦我有
  • Java中未绑定通配符泛型的用途和要点是什么?

    我不明白未绑定通配符泛型有什么用 具有上限的绑定通配符泛型 stuff for Object item stuff System out println item Since PrintStream println 可以处理所有引用类型 通
  • 使用 SAX 进行 XML 解析 |如何处理特殊字符?

    我们有一个 JAVA 应用程序 可以从 SAP 系统中提取数据 解析数据并呈现给用户 使用 SAP JCo 连接器提取数据 最近我们抛出了一个异常 org xml sax SAXParseException 字符引用 是无效的 XML 字符
  • 运行 Jar 文件时出现问题

    我已将 java 项目编译成 Jar 文件 但运行它时遇到问题 当我跑步时 java jar myJar jar 我收到以下错误 Could not find the main class myClass 类文件不在 jar 的根目录中 因
  • Java - 不要用 bufferedwriter 覆盖

    我有一个程序可以将人员添加到数组列表中 我想做的是将这些人也添加到文本文件中 但程序会覆盖第一行 因此这些人会被删除 如何告诉编译器在下一个空闲行写入 import java io import java util import javax
  • 如何测试 spring-security-oauth2 资源服务器安全性?

    随着 Spring Security 4 的发布改进了对测试的支持 http docs spring io spring security site docs 4 0 x reference htmlsingle test我想更新我当前的
  • KeyPressed 和 KeyTyped 混淆[重复]

    这个问题在这里已经有答案了 我搜索过之间的区别KeyPressedand KeyTyped事件 但我仍然不清楚 我发现的一件事是 Keypressed 比 KeyTyped 首先被触发 请澄清一下这些事件何时被准确触发 哪个适合用于哪个目的
  • JAVA - 如何从扫描仪读取文件中检测到“\n”字符

    第一次海报 我在读取文本文件的扫描仪中读取返回字符时遇到问题 正在读取的文本文件如下所示 test txt start 2 0 30 30 1 1 90 30 0 test txt end 第一行 2 表示两个点 第二行 位置索引 0 xp
  • javax.persistence.Table.indexes()[Ljavax/persistence/Index 中的 NoSuchMethodError

    我有一个 Play Framework 应用程序 并且我was使用 Hibernate 4 2 5 Final 通过 Maven 依赖项管理器检索 我决定升级到 Hibernate 4 3 0 Final 成功重新编译我的应用程序并运行它

随机推荐