Utility Methods API for PubNub Android SDK
The methods on this page are utility methods that don't fit into other categories.
Create Push Payload
This method creates the push payload for use in the appropriate endpoint calls.
Method(s)
PushPayloadHelper()
.setApnsPayload(PushPayloadHelper.APNSPayload)
.setFcmPayload(PushPayloadHelper.FCMPayload)
.setCommonPayload(Map<String, Object>)
.build()
Parameter | Type | Required | Description |
---|---|---|---|
setApnsPayload() | APNSPayload | Optional | Set APNs and APNs2 Payload. Associated devices will receive only the data supplied here within the pn_apns key. |
setFcmPayload() | FCMPayload | Optional | Set FCM Payload. Associated devices will receive only the data supplied here within the pn_gcm key. |
setCommonPayload() | Map<String, Object> | Optional | Set common Payload. Native PubNub subscribers will receive the data provided here, together with the pn_apns , and pn_gcm objects. |
build() | Map<String, Object> | Yes | Builds the payload from the values set using the parameters. |
Basic Usage
Create Push Payload
// Create an instance of PushPayloadHelper
PushPayloadHelper pushPayloadHelper = new PushPayloadHelper();
// Setup FCM parameters (FCMPayload)
PushPayloadHelper.FCMPayload fcmPayload = new PushPayloadHelper.FCMPayload();
// The FCMPayload includes a custom Notification object, which FCM itself uses
// to display the message automatically to end-user devices on behalf of the
// client app.
// Notification messages have a predefined set of user-visible keys
PushPayloadHelper.FCMPayload.Notification fcmNotification =
new PushPayloadHelper.FCMPayload.Notification()
.setTitle("Notification title")
.setBody("Notification body text")
.setImage("http://example.com/image.png");
fcmPayload.setNotification(fcmNotification);
show all 82 lines