Receiving a push message

The sample application registers an event listener that listens for invoke events. The invoke event can be a push invoke event or an open invoke event. A push invoke event occurs when the application receives a push message. An open invoke event occurs when a user taps a notification for a push message in the BlackBerry Hub. The following code sample shows you how the sample application handles a push invoke event. To see how the sample application handles an open invoke event, see Handling notifications in the BlackBerry Hub.

This is the event listener that the sample application registers.

// Add an event listener to handle incoming invokes 

The invokeHandler() function first checks to see that the net.rim.blackberry.push.PushService instance is created, and that the application ID is stored.

private function invokeHandler(e:InvokeEvent):void
   if (configService.hasConfiguration()) {
    // The underling net.rim.blackberry.push.PushService instance 
    // might not have been initialized when an invoke first comes in.
    // Make sure that we initialize it here if it hasn't been already.
    // It requires an application ID (for consumer applications) so we 
    // have to check that configuration settings have already been 
    // stored.
	var invokeRequest:InvokeRequest = InvokeManager.invokeManager.
	if (invokeRequest.action == InvokeAction.PUSH) {
    	var pushPayload:PushPayload = pushNotificationService.
    } else if (invokeRequest.action == InvokeAction.OPEN) { 

The function then checks the action property of the invokeRequest to see if it matches the string constant InvokeAction.PUSH. If the property matches the constant, the application extracts the push message from the invoke request using extractPushPayload(). The pushNotificationHandler() function then processes the push message. In your application, you can provide the code to process the push message in a way that's appropriate for your environment.