Class PushModule


  • public class PushModule
    extends BatchModule
    Push Module of Batch
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int NO_COLOR
      Default value for no accent color set by the developer
      static java.lang.String TAG  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void appendBatchData​(android.content.Intent pushIntent, android.content.Intent openIntent)
      Append Batch data to your open intent so that opens from this push will be tracked by Batch and displayed into your dashboard.
      void appendBatchData​(android.os.Bundle pushIntentExtras, android.content.Intent openIntent)
      Append Batch data to your open intent so that opens from this push will be tracked by Batch and displayed into your dashboard.
      void appendBatchData​(com.google.firebase.messaging.RemoteMessage remoteMessage, android.content.Intent openIntent)
      Firebase variant of the method
      void batchWillStart()
      Called by Batch before batch start
      NB : Context & activity are already available from the runtimeManager
      void dismissNotifications()
      Dismiss all app notifications
      void displayNotification​(android.content.Context context, android.content.Intent intent, BatchNotificationInterceptor interceptor, boolean bypassManualMode)
      Call this method to display the notification for this intent.
      void displayNotification​(android.content.Context context, com.google.firebase.messaging.RemoteMessage message, BatchNotificationInterceptor interceptor)
      Call this method to display the notification for Firebase message
      java.lang.Integer getAdditionalIntentFlags()
      User set additional intent flags for notifications.
      AdsIdentifierProvider getAdsIdentifierProvider()
      Get the ads identifier provider associated with the current registration provider
      android.graphics.Bitmap getCustomLargeIcon()
      Return the custom large icon if any.
      int getCustomSmallIconResourceId()
      Return the custom small icon resource if any.
      java.lang.String getId()
      ID of the module
      int getNotificationColor()
      Get the notification color set by the developer
      BatchNotificationInterceptor getNotificationInterceptor()
      Set the developer registered notification interceptor
      java.util.EnumSet<PushNotificationType> getNotificationsType​(android.content.Context context)
      Get the enabled notification types
      Matches what you've set in setNotificationsType.
      Registration getRegistration​(android.content.Context context)
      Get the persisted registration
      java.lang.String getRegistrationID()
      Return the push token if available
      android.net.Uri getSound()
      Get the notification sound uri set by the developer
      int getState()
      Should return the state of the module (usually 0 for deactivated, 1 for activated)
      static boolean isBackgroundRestricted​(android.content.Context context)
      Check if is the app has been restricted by the user.
      boolean isBatchPush​(android.content.Intent intent)
      Check if the received push is a Batch one.
      boolean isBatchPush​(com.google.firebase.messaging.RemoteMessage message)
      Firebase variant
      static boolean isBatchPushServiceAvailable()
      Check if the Push Service is available
      boolean isManualDisplayModeActivated()
      Is manual display mode activated by the developer
      android.app.PendingIntent makePendingIntent​(android.content.Context context, android.content.Intent intent, android.os.Bundle pushIntentExtras)
      Make a PendingIntent suitable for notifications from a given Intent.
      android.app.PendingIntent makePendingIntent​(android.content.Context context, android.content.Intent intent, com.google.firebase.messaging.RemoteMessage message)
      Firebase variant of the method
      android.app.PendingIntent makePendingIntentForDeeplink​(android.content.Context context, java.lang.String deeplink, android.os.Bundle pushIntentExtras)
      Make a PendingIntent suitable for notifications from a given deeplink.
      android.app.PendingIntent makePendingIntentForDeeplink​(android.content.Context context, java.lang.String deeplink, com.google.firebase.messaging.RemoteMessage message)
      Firebase version of the original method
      void onNotificationDisplayed​(android.content.Context context, android.content.Intent intent)
      Call this method when you just displayed a Batch push notification by yourself.
      void onNotificationDisplayed​(android.content.Context context, com.google.firebase.messaging.RemoteMessage message)
      Firebase variant
      static PushModule provide()  
      void refreshRegistration()
      Should be called when push token is updated in background Ex: onTokenRefresh() in a InstanceIDListenerService Ex: onNewToken() in a HsmMessagingService
      void setAdditionalIntentFlags​(java.lang.Integer flags)
      Sets additional intent flags for notifications.
      void setCustomLargeIcon​(android.graphics.Bitmap largeIcon)
      Set the custom large icon.
      void setCustomSmallIconResourceId​(int resourceId)
      Set the custom small icon resource id.
      void setGCMSenderId​(java.lang.String senderId)
      Set the GCM sender id
      void setManualDisplay​(boolean manualDisplay)
      Set manual display mode for push notifications.
      void setNotificationInterceptor​(BatchNotificationInterceptor interceptor)
      Get the developer registered notification interceptor
      void setNotificationsColor​(int argbColor)
      Set the notification accent color for Lollipop or later.
      void setNotificationsType​(java.util.EnumSet<PushNotificationType> types)
      Adjust the way Batch will display notifications.
      You should use this method if you want to remove vibration, light, sound or avoid notifications for this user.
      void setSound​(android.net.Uri soundUri)
      Override the default notification sound uri See Notification.Builder.setSound for more details
      boolean shouldDisplayPush​(android.content.Context context, android.content.Intent intent)
      Should the developer handle and display this push
      boolean shouldDisplayPush​(android.content.Context context, com.google.firebase.messaging.RemoteMessage message)
      Firebase variant
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getCustomSmallIconResourceId

        public int getCustomSmallIconResourceId()
        Return the custom small icon resource if any.
        Returns:
        resource id if any, 0 if not.
      • setCustomSmallIconResourceId

        public void setCustomSmallIconResourceId​(int resourceId)
        Set the custom small icon resource id.
        Parameters:
        resourceId -
      • getAdditionalIntentFlags

        public java.lang.Integer getAdditionalIntentFlags()
        User set additional intent flags for notifications. Can be null.
      • setAdditionalIntentFlags

        public void setAdditionalIntentFlags​(java.lang.Integer flags)
        Sets additional intent flags for notifications. Doesn't work for external deeplinks.
        Parameters:
        flags - Additional flags. "null" to clear.
      • getCustomLargeIcon

        public android.graphics.Bitmap getCustomLargeIcon()
        Return the custom large icon if any.
        Returns:
        resource if any, null if not.
      • setCustomLargeIcon

        public void setCustomLargeIcon​(android.graphics.Bitmap largeIcon)
        Set the custom large icon.
        Parameters:
        largeIcon -
      • setGCMSenderId

        public void setGCMSenderId​(java.lang.String senderId)
        Set the GCM sender id
        Parameters:
        senderId -
      • setNotificationInterceptor

        public void setNotificationInterceptor​(BatchNotificationInterceptor interceptor)
        Get the developer registered notification interceptor
      • getNotificationInterceptor

        public BatchNotificationInterceptor getNotificationInterceptor()
        Set the developer registered notification interceptor
      • dismissNotifications

        public void dismissNotifications()
        Dismiss all app notifications
      • isBatchPush

        public boolean isBatchPush​(android.content.Intent intent)
        Check if the received push is a Batch one. If you have a custom push implementation into your app you should call this method before doing anything else into the BroadcastReceiver.onReceive(Context, Intent) method. If it returns true, you should not handle the push.
        Parameters:
        intent -
        Returns:
        true if the push is for Batch and you shouldn't handle it, false otherwise
      • isBatchPush

        public boolean isBatchPush​(com.google.firebase.messaging.RemoteMessage message)
        Firebase variant
      • getRegistrationID

        public java.lang.String getRegistrationID()
        Return the push token if available
        Returns:
        token if available, null otherwise
      • getRegistration

        public Registration getRegistration​(@NonNull
                                            android.content.Context context)
        Get the persisted registration
      • getNotificationsType

        public java.util.EnumSet<PushNotificationType> getNotificationsType​(android.content.Context context)
        Get the enabled notification types
        Matches what you've set in setNotificationsType.
        Returns:
        Type of notifications you previously set. Be careful, as this can be null if you never used setNotificationsType() or if your context is invalid
      • setNotificationsType

        public void setNotificationsType​(java.util.EnumSet<PushNotificationType> types)
        Adjust the way Batch will display notifications.
        You should use this method if you want to remove vibration, light, sound or avoid notifications for this user.
        Parameters:
        types - Type of notifications you want, default = ALERT + LIGHTS + VIBRATE + SOUND
      • setNotificationsColor

        public void setNotificationsColor​(int argbColor)
        Set the notification accent color for Lollipop or later. See Notification.color for more details
        Parameters:
        argbColor - an ARGB integer like the constants in Color
      • getNotificationColor

        public int getNotificationColor()
        Get the notification color set by the developer
        Returns:
        color if set, NO_COLOR if not
      • setSound

        public void setSound​(android.net.Uri soundUri)
        Override the default notification sound uri See Notification.Builder.setSound for more details
        Parameters:
        soundUri - Sound uri to set on notifications. Null to use the default sound.
      • getSound

        public android.net.Uri getSound()
        Get the notification sound uri set by the developer
        Returns:
        the uri override if set, null if not
      • setManualDisplay

        public void setManualDisplay​(boolean manualDisplay)
        Set manual display mode for push notifications.
        If you set manual display mode to true, no notifications will be shown automatically and you'll have to display it by yourself.
        Parameters:
        manualDisplay -
      • isManualDisplayModeActivated

        public boolean isManualDisplayModeActivated()
        Is manual display mode activated by the developer
        Returns:
      • appendBatchData

        public void appendBatchData​(android.content.Intent pushIntent,
                                    android.content.Intent openIntent)
        Append Batch data to your open intent so that opens from this push will be tracked by Batch and displayed into your dashboard. It also powers other features, such as but not limited to mobile landings.
        Parameters:
        pushIntent - the intent from GCM, that origined this push
        openIntent - the intent of the notification the will be triggered when the user clicks on it
      • appendBatchData

        public void appendBatchData​(android.os.Bundle pushIntentExtras,
                                    android.content.Intent openIntent)
        Append Batch data to your open intent so that opens from this push will be tracked by Batch and displayed into your dashboard. It also powers other features, such as but not limited to mobile landings.
        Parameters:
        pushIntentExtras - the intent extras from GCM, that origined this push
        openIntent - the intent of the notification the will be triggered when the user clicks on it
      • appendBatchData

        public void appendBatchData​(@NonNull
                                    com.google.firebase.messaging.RemoteMessage remoteMessage,
                                    android.content.Intent openIntent)
        Firebase variant of the method
      • makePendingIntent

        @NonNull
        public android.app.PendingIntent makePendingIntent​(@NonNull
                                                           android.content.Context context,
                                                           @NonNull
                                                           android.content.Intent intent,
                                                           @NonNull
                                                           android.os.Bundle pushIntentExtras)
        Make a PendingIntent suitable for notifications from a given Intent. This is useful for custom receivers, or BatchNotificationInterceptor implementations.

        Warning: it will override the intent's action with a unique name, to ensure that existing notifications are not updated with this PendingIntent's content. If you rely on a custom action, you will have to make your own PendingIntent.

        Parameters:
        intent - The intent you want to be triggered when performing the pending intent. Must be an intent compatible with PendingIntent.getActivity(Context, int, Intent, int). Cannot be null.
        pushIntentExtras - Raw extras of the push intent, used to copy data used by Batch to power features such as direct opens, or mobile landings. Cannot be null.
        Returns:
        A PendingIntent instance, wrapping the given Intent.
      • makePendingIntent

        @NonNull
        public android.app.PendingIntent makePendingIntent​(@NonNull
                                                           android.content.Context context,
                                                           @NonNull
                                                           android.content.Intent intent,
                                                           @NonNull
                                                           com.google.firebase.messaging.RemoteMessage message)
        Firebase variant of the method
      • makePendingIntentForDeeplink

        @Nullable
        public android.app.PendingIntent makePendingIntentForDeeplink​(@NonNull
                                                                      android.content.Context context,
                                                                      @NonNull
                                                                      java.lang.String deeplink,
                                                                      @NonNull
                                                                      android.os.Bundle pushIntentExtras)
        Make a PendingIntent suitable for notifications from a given deeplink. It will use Batch's builtin action activity.

        This is useful for custom receivers, BatchNotificationInterceptor or BatchDeeplinkInterceptor implementations.

        Parameters:
        deeplink - Deeplink string. Cannot be null.
        pushIntentExtras - Raw extras of the push intent, used to copy data used by Batch to power features such as direct opens, or mobile landings. Cannot be null.
        Returns:
        A PendingIntent set to open Batch's builtin action activity to open the specified deeplink. Can be null if the deeplink is not valid.
      • makePendingIntentForDeeplink

        @Nullable
        public android.app.PendingIntent makePendingIntentForDeeplink​(@NonNull
                                                                      android.content.Context context,
                                                                      @NonNull
                                                                      java.lang.String deeplink,
                                                                      @NonNull
                                                                      com.google.firebase.messaging.RemoteMessage message)
        Firebase version of the original method
      • shouldDisplayPush

        public boolean shouldDisplayPush​(android.content.Context context,
                                         android.content.Intent intent)
        Should the developer handle and display this push
        Parameters:
        context -
        intent - the gcm push intent
        Returns:
        true if the push is valid and should be handled, false otherwise
      • shouldDisplayPush

        public boolean shouldDisplayPush​(android.content.Context context,
                                         com.google.firebase.messaging.RemoteMessage message)
        Firebase variant
      • displayNotification

        public void displayNotification​(android.content.Context context,
                                        android.content.Intent intent,
                                        BatchNotificationInterceptor interceptor,
                                        boolean bypassManualMode)
        Call this method to display the notification for this intent.
        Parameters:
        context -
        intent - the gcm push intent
      • displayNotification

        public void displayNotification​(android.content.Context context,
                                        com.google.firebase.messaging.RemoteMessage message,
                                        BatchNotificationInterceptor interceptor)
        Call this method to display the notification for Firebase message
      • onNotificationDisplayed

        public void onNotificationDisplayed​(android.content.Context context,
                                            android.content.Intent intent)
        Call this method when you just displayed a Batch push notification by yourself.
        Parameters:
        context -
        intent - the gcm push intent
      • onNotificationDisplayed

        public void onNotificationDisplayed​(android.content.Context context,
                                            com.google.firebase.messaging.RemoteMessage message)
        Firebase variant
      • refreshRegistration

        public void refreshRegistration()
        Should be called when push token is updated in background Ex: onTokenRefresh() in a InstanceIDListenerService Ex: onNewToken() in a HsmMessagingService
      • getAdsIdentifierProvider

        public AdsIdentifierProvider getAdsIdentifierProvider()
        Get the ads identifier provider associated with the current registration provider
        Returns:
      • isBatchPushServiceAvailable

        public static boolean isBatchPushServiceAvailable()
        Check if the Push Service is available
        Returns:
      • isBackgroundRestricted

        public static boolean isBackgroundRestricted​(@NonNull
                                                     android.content.Context context)
        Check if is the app has been restricted by the user. Only available on Android P and forward.
        Parameters:
        context -
        Returns:
      • getId

        public java.lang.String getId()
        Description copied from class: BatchModule
        ID of the module
        Specified by:
        getId in class BatchModule
        Returns:
      • getState

        public int getState()
        Description copied from class: BatchModule
        Should return the state of the module (usually 0 for deactivated, 1 for activated)
        Specified by:
        getState in class BatchModule
        Returns:
      • batchWillStart

        public void batchWillStart()
        Description copied from class: BatchModule
        Called by Batch before batch start
        NB : Context & activity are already available from the runtimeManager
        Overrides:
        batchWillStart in class BatchModule