BlackBerry Registration: To send a registration request to BlackBerry, create an object of the BlackberryRegistration class and call the method register with theblackberryAppId (application ID that was sent to you by RIM). The method returns the registration response from the BlackBerry Infrastructure.
BlackBerryRegistration blackberryRegistration = new BlackBerryRegistration(); blackberryRegistration.register(BLACKBERRY_APP_ID); |
BlackBerry Un-Registration: To un-register the device from receiving Xtify notifications through the BlackBerry infrastructure, call the method unRegister with blackberryAppId(application ID that was sent to you by RIM). The method returns the response from the BlackBerry Infrastructure.
blackberryRegistration.unRegister(BLACKBERRY_APP_ID); |
NOTE: To prevent registration / un-registration from blocking the user interface or other tasks, you should run them in a separate thread.
To send a registration request to Xtify, create an object of XtifyRegistration class and call the method register with xtifyAppKey (the Xtify application key that you created in the Xtify Console). The method returns the registration response from the Xtify servers.
XtifyRegistration xtifyRegistration = new XtifyRegistration(); xtifyRegistration.register(XTIFY_API_KEY); |
NOTE: To prevent registration from blocking the user interface or other tasks, you should run it in a separate thread.
To receive a push notification, create an object of PushNotificationListener class and set blackberryPushPort value to the application push port value that was sent to you by RIM. Start the thread to listen to incoming push notifications.
PushNotificationListener pushNotificationListener = new PushNotificationListener(); pushNotificationListener.setBlackberryPushPort(BLACKBERRY_PUSH_PORT); pushNotificationListener.start(); |
In the PushNotificationListener class the method onMessage is called when the application receives a new notification that includes the content of that notification (notificationContent). Your code that processes the notification message should be placed inside the method onMessage.
Note: To display /remove the application icon on the BlackBerry notification bar:
private static EncodedImage mImageGreen = EncodedImage.getEncodedImageResource("img/ indicator.png");
private static ApplicationIcon mIconGreen = new ApplicationIcon(mImageGreen);
private static ApplicationIcon mmIcon = mIconGreen;
.
.
.
//Displaying the icon on the BlackBerry notification bar.
ApplicationIndicatorRegistry reg = ApplicationIndicatorRegistry.getInstance();
ApplicationIndicator indicator = reg.register(mmIcon, false, true);
.
.
//Removing notification bar icon
ApplicationIndicatorRegistry reg = ApplicationIndicatorRegistry.getInstance();
reg.unregister(); |
If you want to take advantage of the Xtify location capabilities, create an object of LocationHandler class and call updateLocation with your Xtify application key.
LocationHandler locationHandler = new LocationHandler(); locationHandler.updateLocation(XTIFY_APP_KEY); |
Note: The updateLocation method only gets the location and sends it to the Xtify servers once per call. In order to implement continuous location updates you can implement the J2ME LocationListener interface, or extend TimerTask and call updateLocation on a specific interval.