• BlackBerry Dynamics
  • Runtime library for Android applications
  • 12.0.1.79
Single-Source Push Channel Listener or Delegate
Deprecated:
This class is deprecated and will be removed in a future release. Instead of setting a PushChannel listener, register for notifications as described in the PushChannel class reference.

State changes that occur when using PushChannel are handled by creating a class that implements this protocol. The callback for handling received Push Channel notifications is also part of this protocol.

Code Snippets

The following code snippets illustrate some common tasks.

Receive Push Channel Token

public void onChannelOpen(String token) {
System.out.println("onChannelOpen token: " + token);
myApp.pushIsOpen = true;
myApp.pushToken = token;
myApp.sendPushToken();
}

The above snippet shows a simple onChannelOpen handler. The following takes place when the Push Channel is opened:

The sendPushToken method, which would be written by the application developer, would send the token to the application server. This could use a socket, an HTTP request, or another means of communication. From the Push Channel point of view, this is an out-of-band communication.

The server will use the token to address Push Channel notification messages back to the application. These would be received by the application's onChannelMessage handler.

Receive Push Channel notification

public void onChannelMessage(String data) {
System.out.println("onChannelMessage: " + data);
myApp.processPush(data);
}

The above snippet shows a simple onChannelMessage handler.

The handler logs the received data to the system monitor, then calls the application processPush method. The "payload" of the notification is passed as a parameter to the processPush method.

The processPush method, which would be written by the application developer, could initiate any of the following actions:

Handle Channel Closure

public void onChannelClose(String data) {
System.out.println("onChannelClose: " + data);
myApp.pushIsOpen = false;
myApp.discardPushToken(data);
}

The above snippet shows a simple onChannelClose handler. The following takes place when the Push Channel is closed:

The discardPushToken method would delete the application's copy of the token, possibly after checking that it matches the whichWas parameter. The method could also initiate connection of a new Push Channel, which would have a new token. See connect .

Handle Channel Error

public void onChannelError(int error) {
System.out.println("onChannelError: " + error);
myApp.pushIsOpen = false;
myApp.pushErr = error;
myApp.discardPushToken();
}

The above snippet shows a simple onChannelError handler.

The handler logs the error code to the system monitor, flags the channel's state as not connected, records the error code in the application, then calls the application discardPushToken method.

The discardPushToken method could do any of the following:

Handle Ping Failure

pubic void onChannelPingFail(int error) {
System.out.println("onChannelPingFail: " + error);
if ( error == 605 ) {
myApp.resendPushToken();
}
}

The above snippet shows a simple onChannelPingFail handler.

The handler logs the error code to the system monitor, then calls the application resendPushToken method if the token was lost.

The resendPushToken method, which would be written by the application developer, would send the application's stored token to the application server. This could use a socket, an HTTP request, or another means of communication. From the Push Channel point of view, this is an out-of-band communication.

The resendPushToken method should expect that the server is not immediately available, perhaps employing a retry policy.