Manage Push Channel tokens and notifications. More...
The Push Channel framework is a BlackBerry Dynamics feature used to receive notifications from an application server.
Use of the Push Channel feature in the application is dependent on:
Push Channel data communication doesn't go via the proxy specified in the native settings of the device or computer on which the application is running, if any.
Push Channels are established by the BlackBerry Dynamics application, then used by the application server when needed. The sequence of events is as follows.
The BlackBerry Dynamics platform keeps data communications between the application and server alive while the application is waiting for a Push Channel notification. This is achieved by sending "heartbeat" messages at an interval that is dynamically optimized for battery and network performance.
Ping Failure is an optional feature of the Push Channel framework. The application server can register a ping address after receiving the Push Channel token from the mobile application.
If the application server registers a ping address, then it will be periodically checked ("pinged") by the BlackBerry Dynamics Network Operation Center (NOC). If the server does not respond to a ping, then the NOC notifies the application that requested the corresponding Push Channel.
The purpose of this feature is to support servers that lose the Push Channel token when they are restarted.
See the Push Channel Back-End API for details of Ping Failure registration.
The Push Channel programming interface is asynchronous and state-based. The application code creates a Push Channel object for each channel it will use, typically one per application server. When a channel changes state, or a channel event occurs, the BlackBerry Dynamics runtime notifies the application.
To notify the application, the runtime sends an Intent, by local broadcast. The attributes of the Intent and its Bundle will specify the channel, and the details of the change or event that is being notified.
For all notifications:
action
will be the GD_PUSH_CHANNEL_EVENT_ACTION value.The application registers its receivers for Push Channel notifications by calling the GDAndroid.registerReceiver method.
The availability of methods in the Push Channel programming interface, and what actions take place, are detailed below, and summarized in the following table. The table also summarizes which notifications are expected in each state.
State | Methods and actions | Expected notifications See Push Channel Constants |
---|---|---|
Prepared | Application can call connect : state becomes Connecting | None |
Connecting | BlackBerry Dynamics runtime requests a new channel from the proxy infrastructure | Error : new state is FailedOpen : new state is Open |
Open | Application can call disconnect : state becomes Disconnecting | Message : no state changePingFail : no state changeClose : new state is Disconnected |
Disconnecting | BlackBerry Dynamics Runtime requests the proxy infrastructure to close the channel | Message : no state changePingFail : no state changeClose : new state is Disconnected |
Disconnected | Application can call connect : state becomes Connecting | None |
Failed | Application can call connect : state becomes Connecting | None |
The transitions in the above table are also shown in this diagram.
Note that an individual Push Channel might or might not be closed when the overall Push Channel service becomes unavailable.
Every Push Channel must have an identifier. Identifiers must be unique within an application. A Push Channel identifier is a text string set by the application code. Note that Push Channel identifiers aren't the same as Push Channel tokens. Token values are set by the BlackBerry Dynamics infrastructure and runtime.
The following convention represents best practice for Push Channel identifiers.
A Push Channel identifier should be composed of a domain followed by a module name and an optional purpose. The parts are separated by full stops (periods). The following examples illustrate the convention.
Example: com.example.mobile-life.email
Example: com.example.dashboard
The rules for identifier part values are as follows.
The following code snippets illustrate some common tasks.
The following snippet shows a Push Channel being created and opened after checking that the service is available.
The above snippet shows the following taking place:
The attempt is asynchronous. The associated Open
notification would be received if and when the attempt is succesful (not shown).
The above snippet shows: Request to disconnect the Push Channel.
The request is asynchronous. The associated Close
notification would be received when the closure is finalized (not shown).
The following code snippets illustrate some common tasks.
The following snippet shows a simple handler for when a Push Channel opens.
The above snippet shows the following taking place:
sendPushToken
method in the application is called.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 Push Channel event handler code.
The above snippet shows the following taking place when a Push Channel message is received:
processPush
method in the application is called and passed the content of the message.The processPush
method, which would be written by the application developer, could initiate any of the following actions:
The above snippet shows a simple channel closure handler. The following takes place when the Push Channel is closed:
discardPushToken
method is called. The token of the closed channel is passed as a parameter.The discardPushToken
method would delete the application's copy of the token, possibly after checking that it matches the previous stored token.
The method could also initiate connection of a new Push Channel, which would have a new token. See connect .
The above snippet shows a simple Error
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:
See under Ping Failure in the Push Channel Back-End API for an explanation of the Ping Failure feature.
The above snippet shows a simple Ping Failure 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.
Public Member Functions | |
PushChannel (String pushChannelIdentifier) | |
Constructor that prepares a new Push Channel. More... | |
void | connect () |
Connect Push Channel. More... | |
void | disconnect () |
Disconnect Push Channel. More... | |
PushChannelState | getState () |
Push Channel state. More... | |
String | getDataPath () |
Intent data path for filtering at the receiver. More... | |
String | getDataScheme () |
Intent data scheme for filtering at the receiver. More... | |
String | getDataAuthority () |
Intent data authority for filtering at the receiver. More... | |
IntentFilter | prepareIntentFilter () |
Intent Filter for receiver registration. More... | |
Static Public Member Functions | |
static PushChannelEventType | getEventType (Intent intent) |
Get event type from Push Channel notification. More... | |
static String | getToken (Intent intent) |
Get Push Channel token from notification. More... | |
static String | getPushChannelHost (Intent intent) |
Get Push Channel Host Name from notification. More... | |
static String | getMessage (Intent intent) |
Get message data from Push Channel notification. More... | |
static int | getErrorCode (Intent intent, int defaultValue) |
Get error code from Push Channel notification. More... | |
static int | getPingFailCode (Intent intent, int defaultValue) |
Get ping failure reason code from Push Channel notification. More... | |
Static Public Attributes | |
static final String | GD_PUSH_CHANNEL_EVENT_ACTION = "com.good.gd.PUSH_CHANNEL_EVENT" |
Intent action for Push Channel notifications. More... | |
PushChannel | ( | String | pushChannelIdentifier | ) |
Call this method to construct a new Push Channel object. This method does not initiate data communication. See connect .
pushChannelIdentifier | String containing the identifier for this Push Channel, see under Push Channel Identifiers, above. |
com.good.gd.error.GDNotAuthorizedError | if BlackBerry Dynamics authorization processing has not yet completed. |
void connect | ( | ) |
Call this method to open the Push Channel connection. This method can only be called when the channel isn't open.
This method causes a request for a Push Channel to be sent to the BlackBerry Dynamics Network Operation Center (NOC). The NOC will create the channel, and issue a Push Channel token, which can then be used to identify the channel.
The connection attempt is asynchronous. An Intent with a Bundle will be sent by local broadcast to notify the application of the result. If the attempt succeeds, the Bundle will have an event type of PushChannelEventType.Open
, and will contain the token. If the attempt fails, the Bundle will instead have an event type of PushChannelEventType.Error
, and will contain an error code. The following class methods can be used to extract the values from the Bundle.
com.good.gd.error.GDNotAuthorizedError | if BlackBerry Dynamics authorization processing has not yet completed. |
void disconnect | ( | ) |
Call this method to initiate permanent disconnection of the Push Channel. This method can only be called when the channel is open.
This method causes a request for Push Channel termination to be sent to the BlackBerry Dynamics Network Operation Center (NOC). The NOC will delete the channel, and invalidate the Push Channel token that was issued when the channel was initially opened, see connect .
Disconnection is asynchronous. When disconnection is complete, an Intent with a Bundle is sent by local broadcast to notify the application. The Bundle will have an event type of PushChannelEventType.Close
. The following class method can be used to extract the value from the Bundle.
Note. This method is for permanent closure of the channel. Transient suspension of Push Channel notifications may be more easily accomplished out-of-band, by direct communication with the application server.
If the connection with the NOC is open and operating, and the application server that was sent the token registered for isDisconnected
, then a disconnect notification will be sent to the application server, by the NOC. See the Push Channel Back-End API.
com.good.gd.error.GDNotAuthorizedError | if BlackBerry Dynamics authorization processing has not yet completed. |
PushChannelState getState | ( | ) |
PushChannelState
value for the current state of the channel that corresponds to this instance. String getDataPath | ( | ) |
This method returns the Intent data path for Push Channel notifications on this channel. The prepareIntentFilter method returns an Intent Filter that uses this value. This separate method is provided for completeness.
String
containing the Intent data path for this channel. String getDataScheme | ( | ) |
This method returns the Intent data scheme for Push Channel notifications on this channel. The prepareIntentFilter method returns an Intent Filter that uses this value. This separate method is provided for completeness.
String
containing the Intent data scheme for this channel. String getDataAuthority | ( | ) |
This method returns the Intent data authority for Push Channel notifications on this channel. The prepareIntentFilter method returns an Intent Filter that uses this value. This separate method is provided for completeness.
String
containing the Intent data authority for this channel. IntentFilter prepareIntentFilter | ( | ) |
This method returns an Intent Filter that will match Push Channel notifications on the channel that corresponds to the PushChannel
instance.
The Intent Filter will be based on the GD_PUSH_CHANNEL_EVENT_ACTION
action string, and the values that would be returned by the getDataScheme
, getDataAuthority
, and getDataPath
methods. This method is a shortcut.
android.content.IntentFilter
instance that is suitable to pass to the GDAndroid.registerReceiver method.
|
static |
intent | Intent that was sent by local broadcast for a Push Channel notification. |
PushChannelEventType
value for the type of event being notified. See Push Channel Constants for documentation.
|
static |
This method is a helper that returns the Push Channel token from a notification Intent.
Before calling this method, call getEventType to check that the notification is for an event of a type that contains a token:
intent | Intent that was sent by local broadcast for a Push Channel notification. |
String
containing the Push Channel token.
|
static |
This method is a helper that returns the Push Channel Host from a notification Intent.
Before calling this method, call getEventType to check that the notification is for an event of a type that contains a token:
intent | Intent that was sent by local broadcast for a Push Channel notification. |
String
containing the Push Channel Host Name or null if the Host Name is not applicable.
|
static |
This method is a helper that returns the Push Channel message data from a notification Intent.
Before calling this method, call getEventType to check that the notification is for a PushChannelEventType.Message
event.
intent | Intent that was sent by local broadcast for a Push Channel notification. |
String
containing the message.
|
static |
This method is a helper that returns the error code from a Push Channel notification Intent.
Before calling this method, call getEventType to check that the notification is for a PushChannelEventType.Error
event.
intent | Intent that was sent by local broadcast for a Push Channel notification. |
defaultValue | int to return in case there is no error code in the notification. |
int
error code, if present in intent
, or the defaultValue
otherwise.
|
static |
This method is a helper that returns the ping failure reason code from a Push Channel notification Intent.
Before calling this method, call getEventType to check that the notification is for a PushChannelEventType.PingFail
event.
intent | Intent that was sent by local broadcast for a Push Channel notification. |
defaultValue | int to return in case there is no ping failure code in the notification. |
int
ping failure code, if present in intent
, or the defaultValue
otherwise.
|
static |
Intent action string for Push Channel notifications. The prepareIntentFilter method returns an Intent Filter that uses this value. This separate constant is provided for completeness.