Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Blackberry 弹出屏幕显示黑莓推送通知信息_Blackberry_Java Me - Fatal编程技术网

Blackberry 弹出屏幕显示黑莓推送通知信息

Blackberry 弹出屏幕显示黑莓推送通知信息,blackberry,java-me,Blackberry,Java Me,已将此链接用于推送通知 代码运行良好,我在对话框中收到推送通知,但我没有显示默认对话框,而是创建了自己的弹出屏幕来显示推送消息 但是我的PushMessageReader.java中出现了错误,您可以在链接中检查。下面是我的PushMessageReader.java代码,用于显示推送消息的弹出屏幕 public final class PushMessageReader { // HTTP header property that carries unique push messag

已将此链接用于推送通知

代码运行良好,我在对话框中收到推送通知,但我没有显示默认对话框,而是创建了自己的弹出屏幕来显示推送消息

但是我的PushMessageReader.java中出现了错误,您可以在链接中检查。下面是我的PushMessageReader.java代码,用于显示推送消息的弹出屏幕

public final class PushMessageReader {

    // HTTP header property that carries unique push message ID
    private static final String MESSAGE_ID_HEADER = "Push-Message-ID";
    // content type constant for text messages
    private static final String MESSAGE_TYPE_TEXT = "text";
    // content type constant for image messages
    private static final String MESSAGE_TYPE_IMAGE = "image";

    private static final int MESSAGE_ID_HISTORY_LENGTH = 10;
    private static String[] messageIdHistory = new String[MESSAGE_ID_HISTORY_LENGTH];
    private static byte historyIndex;

    private static byte[] buffer = new byte[15 * 1024];
    private static byte[] imageBuffer = new byte[10 * 1024];

    static Popupscreen popup;
    private static String text;


    /**
     * Utility classes should have a private constructor.
     */
    private PushMessageReader() {
        popup = new Popupscreen();
    }


    /**
     * Reads the incoming push message from the given streams in the current thread and notifies controller to display the information.
     * 
     * @param pis
     *            the pis
     * @param conn
     *            the conn
     */
    public static void process(PushInputStream pis, Connection conn) {
        System.out.println("Reading incoming push message ...");

        try {

            HttpServerConnection httpConn;
            if (conn instanceof HttpServerConnection) {
                httpConn = (HttpServerConnection) conn;
            } else {
                throw new IllegalArgumentException("Can not process non-http pushes, expected HttpServerConnection but have "
                        + conn.getClass().getName());
            }

            String msgId = httpConn.getHeaderField(MESSAGE_ID_HEADER);
            String msgType = httpConn.getType();
            String encoding = httpConn.getEncoding();

            System.out.println("Message props: ID=" + msgId + ", Type=" + msgType + ", Encoding=" + encoding);


            boolean accept = true;
            if (!alreadyReceived(msgId)) {
                byte[] binaryData;

                if (msgId == null) {
                    msgId = String.valueOf(System.currentTimeMillis());
                }

                if (msgType == null) {
                    System.out.println("Message content type is NULL");
                    accept = false;
                } else if (msgType.indexOf(MESSAGE_TYPE_TEXT) >= 0) {
                    // a string
                    int size = pis.read(buffer);
                    binaryData = new byte[size];
                    System.arraycopy(buffer, 0, binaryData, 0, size);   

                    PushMessage message = new PushMessage(msgId, System.currentTimeMillis(), binaryData, true, true );
                    text = new String( message.getData(), "UTF-8" );

                    System.out.println("PUSH MESSAGE================ "+text);
                     try{
                            /*final Dialog screen = new Dialog(Dialog.D_OK_CANCEL, " "+text,Dialog.OK,
                                    //mImageGreen.getBitmap(),
                                    null, Manager.VERTICAL_SCROLL);*/

                            final UiEngine ui = Ui.getUiEngine();

                            Application.getApplication().invokeAndWait(new Runnable() {

                                public void run() {

                                    NotificationsManager.triggerImmediateEvent(0x749cb23a76c66e2dL, 0, null, null);

                                    ui.pushGlobalScreen(popup, 0, UiEngine.GLOBAL_QUEUE);

                                }
                            });

                            //screen.setDialogClosedListener(new MyDialogClosedListener());
                            }

                     catch (Exception e) {
                                // TODO: handle exception
                            }


                    // TODO report message
                }  else {
                    System.out.println("Unknown message type " + msgType);
                    accept = false;
                }
            } else {
                System.out.println("Received duplicate message with ID " + msgId);
            }
            pis.accept();
        } catch (Exception e) {
            System.out.println("Failed to process push message: " + e);
        }
    }

    /**
     * Check whether the message with this ID has been already received.
     * 
     * @param id
     *            the id
     * @return true, if successful
     */
    private static boolean alreadyReceived(String id) {
        if (id == null) {
            return false;
        }

        if (Arrays.contains(messageIdHistory, id)) {
            return true;
        }

        // new ID, append to the history (oldest element will be eliminated)
        messageIdHistory[historyIndex++] = id;
        if (historyIndex >= MESSAGE_ID_HISTORY_LENGTH) {
            historyIndex = 0;
        }
        return false;
    }

    class Popupscreen extends PopupScreen{

        LabelField label = new LabelField("");

        ButtonField Okbutn;

        public Popupscreen(){
            super(new VerticalFieldManager(), Screen.DEFAULT_CLOSE); 

            Okbutn = new ButtonField("ok",ButtonField.FIELD_HCENTER);

            LabelField lbl = new LabelField("SUNRAYS", LabelField.USE_ALL_WIDTH | DrawStyle.HCENTER){
                 protected void paintBackground(net.rim.device.api.ui.Graphics g)
                    {
                        g.clear();
                        g.getColor();
                        //g.setColor(Color.WHITESMOKE);
                        //g.fillRect(0, 0, Display.getWidth(), Display.getHeight());
                        g.setColor(Color.WHITESMOKE);               
                    }
             };


             add(lbl);
             add(label); 
             add(Okbutn); 

             label.setText(text);

             Okbutn.setChangeListener(new FieldChangeListener() {

                public void fieldChanged(Field field, int context) {
                    // TODO Auto-generated method stub

                    close();
                }
            });
             //this.setBackground(BackgroundFactory.createSolidTransparentBackground(Color.WHITE, 80));

            // setBorder(BorderFactory.createSimpleBorder(new XYEdges(),Border.STYLE_TRANSPARENT)); 

        }

    }
}

我可以知道你得到的错误吗?你能告诉我什么是弹出窗口吗?弹出窗口意味着我想打开弹出窗口,正如你在我上面发布的代码中看到的那样..,我得到的是NullPointerException你的代码扩展了应用程序类。不是应用程序。