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.
-
Import the required classes and interfaces.
import net.rim.device.api.io.messaging.*;
-
Initialize a
NonBlockingReceiverDestination variable to manage
the subscription.
NonBlockingReceiverDestination nbrd = null;
-
Create a
MessageListener object to process incoming push
messages.
try
{
MyMessageListener pushListener = new MyMessageListener();
-
Create a
URI object with the port information that the
content provider assigns to you.
URI pushURI = URI.create("http://:101");
-
Create an
InboundDestinationConfiguration object to set
parameters for the push subscription.
InboundDestinationConfiguration config =
InboundDestinationConfigurationFactory.createBPSConfiguration
(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
-
Create a
NonBlockingReceiverDestination.
nbrd = DestinationFactory.createNonBlockingReceiverDestination
(config, pushURI, pushListener);
-
Create a
SenderDestination to send a subscription message.
NonBlockingSenderDestination bpsDestination = DestinationFactory.createNonBlockingSenderDestination
(myContext, uri, responseListener);
-
Configure a subscription message.
ByteMessage subMsg = BpsSubscriptionMessageBuilder.createByteSubscriptionMessage
(bpsDestination, nbrd, "user", "pwd");
-
Send the subscription message.
bpsDestination.send(subMsg);
Was this information helpful? Send us your comments.