Subscribe to a push initiator

This task focuses on creating a subscription message and the NonBlockingReceiverDestination object for a Push Service subscription. You must send your subscription message using a SenderDestination object, or by creating a network connection manually.
Before you begin: Obtain an application ID and the local port number that your application should use to listen for incoming messages. These details are provided to the content provider that creates a server-side push application.
  1. Import the required classes and interfaces.
  2. Initialize a NonBlockingReceiverDestination variable to manage the subscription.
    NonBlockingReceiverDestination nbrd = null;
  3. Create a MessageListener object to process incoming push messages.
        MyMessageListener pushListener = new MyMessageListener();
  4. Create a URI object with the port information that the content provider assigns to you.
    URI pushURI = URI.create("http://:101");
  5. Create an InboundDestinationConfiguration object to set parameters for the push subscription.
        InboundDestinationConfiguration config = 
                (true, // start this application when a push message arrives
                 false, // allow other applications to receive these push messages
                 false, // do not store these messages (persistence not supported)
                 "12-Ab234cD5eF67h890", // application ID,
                 BPSuri); // BlackBerry Push Service URI
  6. Create a NonBlockingReceiverDestination.
        nbrd = DestinationFactory.createNonBlockingReceiverDestination
                   (config, pushURI, pushListener);
  7. Create a SenderDestination to send a subscription message.
        NonBlockingSenderDestination bpsDestination = DestinationFactory.createNonBlockingSenderDestination
                                  (myContext, uri, responseListener);
  8. Configure a subscription message.
        ByteMessage subMsg = BpsSubscriptionMessageBuilder.createByteSubscriptionMessage
                                 (bpsDestination, nbrd, "user", "pwd");
  9. Send the subscription message.

Was this information helpful? Send us your comments.