BlackBerry - Receive Push Message inside App

不打扰是莪最后的温柔 提交于 2019-12-11 05:44:23

问题


I have successfully developed a BlackBerry App that registers for BlackBerry Push Messaging Service and receives push message. The Push Message is received as a pop-up message. I am handling at the back end to show this message inside the App in a Chat Screen that I have created. The push message when sent to the device is stored in a database as well. The App has a timer running that queries the database for any new message and displays it inside the app. However this approach is not so efficient as I aim to display the message as soon as it is sent as a push message. My questions are as follow:

  1. When the App is closed and the server sends a push message, will this message be delivered?
  2. When a push message is received, how do you force-start an app?
  3. Is there any particular API or method available to detect when a push message is received?
  4. I am able to change the App icon when a message is received. However, I want this to change as soon as the push message is received as the pop-up. So how can I detect when the push message is received other than running a background timer?

Please guide.


回答1:


I would agree that polling a database for new messages is not a good solution.

What I would do is to implement two entry points in your app:

1) A background process, that extends the BlackBerry Application class. This is non-graphical, and will listen for push notifications.

2) A normal UI, which I think you're referring to as "the App". This will extend the UiApplication class.

When your background process receives push notifications, you can then choose to open up the UiApplication so your user can handle the new chat message.

To answer your questions:

  1. Yes, the push notification will be received, because the background process is always running (you should make sure to check the Autorun at Startup box in the BlackBerry_App_Descriptor.xml file, for the background entry point). See more here.

  2. The background process can bring the UI application to the foreground with this code.

  3. There's multiple ways to receive push notifications ... see links below. It sounds like you already have this implemented. I think the key, though, is that you put your push handling code in the background Application. Then, your UI application doesn't need any special APIs. Your background application simply opens the UI when it's time. It can choose to pass data to the UI application with this technique.

  4. Again, you'll want to setup two entry points: one background Application, and one normal UiApplication. The background application will run on startup, register for push notifications, and receive push notifications as they come in (without polling). You can then decide what to do, including opening up your UI (UiApplication).

More on Push and Entry Points

  • http://devblog.blackberry.com/2010/06/super-apps-java-series-running-in-the-background-part-1/

  • When you download the Push SDK, you'll find sample code in there.

  • Within the BlackBerry Eclipse Plugin, you can Import... -> Import BlackBerry Samples -> HTTPPushDemo for more demo source.

  • Tutorial: Making an app push-enabled (OS 6.0+)



来源:https://stackoverflow.com/questions/18606610/blackberry-receive-push-message-inside-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!