Class BatchPushPayload

java.lang.Object
com.batch.android.BatchPushPayload
All Implemented Interfaces:
PushUserActionSource, UserActionSource

public class BatchPushPayload extends Object implements PushUserActionSource
Convenience object to retrieve standardized Batch data out of a Batch Push intent.
This class does not have a public constructor. You must use payloadFromBundle(android.os.Bundle) or payloadFromReceiverIntent(android.content.Intent)
  • Method Details

    • payloadFromBundle

      public static BatchPushPayload payloadFromBundle(Bundle bundle) throws BatchPushPayload.ParsingException
      Attempt to extract the Batch Push data contained within the specified Bundle.
      This is usually the method you want to use when reading this payload from an activity opened by Batch, or when you wrote an existing BatchPushPayload to a Bundle/Intent extras using writeToBundle(android.os.Bundle) / writeToIntentExtras(android.content.Intent).
      Parameters:
      bundle - Bundle containing Batch Push data. Parsed data is read from the key defined by Batch.Push#PAYLOAD_KEY.
      Returns:
      A BatchPushPayload instance.
      Throws:
      BatchPushPayload.ParsingException - Thrown if the argument doesn't contain valid Batch Push data
    • payloadFromReceiverIntent

      public static BatchPushPayload payloadFromReceiverIntent(Intent intent) throws BatchPushPayload.ParsingException
      Attempt to extract the Batch Push data contained within the specified Intent.
      This is usually the method you want to use when reading this payload from a push broadcast receiver/service, NOT from an activity intent. If you wrote an existing BatchPushPayload to a Bundle/Intent extras using writeToBundle(android.os.Bundle) / writeToIntentExtras(android.content.Intent), you should rather use payloadFromBundle(android.os.Bundle)
      Parameters:
      intent - Broadcast receiver intent containing Batch Push data.
      Returns:
      A BatchPushPayload instance.
      Throws:
      BatchPushPayload.ParsingException - Thrown if the argument doesn't contain valid Batch Push data
    • payloadFromReceiverExtras

      public static BatchPushPayload payloadFromReceiverExtras(Bundle extras) throws BatchPushPayload.ParsingException
      Attempt to extract the Batch Push data contained within the specified Intent extras.
      This is usually the method you want to use when reading this payload from a push broadcast receiver/service, NOT from an activity intent. If you wrote an existing BatchPushPayload to a Bundle/Intent extras using writeToBundle(android.os.Bundle) / writeToIntentExtras(android.content.Intent), you should rather use payloadFromBundle(android.os.Bundle)
      Parameters:
      extras - Broadcast receiver intent's extras containing Batch Push data.
      Returns:
      A BatchPushPayload instance.
      Throws:
      BatchPushPayload.ParsingException - Thrown if the argument doesn't contain valid Batch Push data
    • payloadFromFirebaseMessage

      public static BatchPushPayload payloadFromFirebaseMessage(com.google.firebase.messaging.RemoteMessage remoteMessage) throws BatchPushPayload.ParsingException
      Attempt to extract the Batch Push data contained within the specified Firebase RemoteMessage.
      This is usually the method you want to use when reading this payload from a FirebaseMessagingService implementation, NOT from an activity intent. If you wrote an existing BatchPushPayload to a Bundle/Intent extras using writeToBundle(android.os.Bundle) / writeToIntentExtras(android.content.Intent), you should rather use payloadFromBundle(android.os.Bundle)
      Parameters:
      remoteMessage - Firebase remote message containing Batch Push data.
      Returns:
      A BatchPushPayload instance.
      Throws:
      BatchPushPayload.ParsingException - Thrown if the argument doesn't contain valid Batch Push data
    • writeToBundle

      public void writeToBundle(Bundle bundle)
      Serialize this instance into a Bundle.
      Note that you'll need to use payloadFromBundle(android.os.Bundle) with the intent's extras to read it back.
      Parameters:
      bundle - Bundle instance to serialize this in
    • writeToIntentExtras

      public void writeToIntentExtras(Intent intent)
      Serialize this instance into an Intent. Note that you'll need to use payloadFromBundle(android.os.Bundle) with the intent's extras to read it back.
      This method WILL NOT fill the intent in a format that payloadFromReceiverIntent(android.content.Intent) understands.
      Parameters:
      intent - Intent instance to serialize this in
    • hasDeeplink

      public boolean hasDeeplink()
      Does this push contains a deeplink
      Returns:
      true if this push contains a deeplink, false otherwise
    • getDeeplink

      public String getDeeplink()
      Get the deeplink url contained in this push.
      You should always check if the push contains a deeplink using hasDeeplink()
      Returns:
      the deeplink if any, null otherwise
    • hasCustomLargeIcon

      public boolean hasCustomLargeIcon()
      Does this push contains a custom large icon
      Returns:
      true if this push contains a custom large icon to download, false otherwise
    • getCustomLargeIconURL

      public String getCustomLargeIconURL(Context context)
      Get the custom large icon url contained in this push.
      You should always check if the push contains a custom large icon using hasCustomLargeIcon().

      The url returned by this method is already optimized for the device, you have to download the image and use it in the notification
      Returns:
      the custom large icon url if any, null otherwise
    • hasBigPicture

      public boolean hasBigPicture()
      Does this push contains a big picture
      Returns:
      true if this push contains a big picture to download, false otherwise
    • getBigPictureURL

      public String getBigPictureURL(Context context)
      Get the big picture url contained in this push.
      You should always check if the push contains a big picture using hasBigPicture().

      The url returned by this method is already optimized for the device, you have to download the image and use it in the notification
      Returns:
      the big picture url if any, null otherwise
    • hasLandingMessage

      public boolean hasLandingMessage()
      Whether the payload contains a landing message or not
    • getLandingMessage

      public BatchMessage getLandingMessage()
      Returns the landing message that's in this payload if there is one.
      Returns:
      the landing message, if there is one
    • getActions

      public List<BatchNotificationAction> getActions()
      Get the actions associated with this push, if any.
    • getPriority

      @Deprecated public int getPriority()
      Deprecated.
      Since Android 8.0, "priority" became "importance", and is now set on the channel itself. You should infer the priority from the channel, using getChannel()
      Get the notification priority

      This integer value is the same one as priorities defined in NotificationCompat

    • getGroup

      public String getGroup()
      Get the notification group name. Meant to be used with NotificationCompat.Builder.setGroup(String)
      Returns:
      Group name string, null if none
    • isGroupSummary

      public boolean isGroupSummary()
      Get the notification group name. Meant to be used with NotificationCompat.Builder.setGroupSummary(boolean)
      Returns:
      Whether this notification should be a group summary or not
    • getChannel

      public String getChannel()
      Get the desired notification channel. Meant to be used with NotificationCompat.Builder.setChannelId(String)
      Returns:
      The notification channel this push should be displayed on, if applicable. Can be null.
    • getPushBundle

      public Bundle getPushBundle()
      Get the raw push bundle
      Specified by:
      getPushBundle in interface PushUserActionSource