Class Batch.Push
- java.lang.Object
-
- com.batch.android.Batch.Push
-
- Enclosing class:
- Batch
public static final class Batch.Push extends java.lang.Object
Batch Push module
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ALERT_KEY
Key to retrieve the Alert messagestatic java.lang.String
BODY_KEY
Key to retrieve the body of a push messagestatic java.lang.String
PAYLOAD_KEY
Key to retrieve the GCM payload from the activity launch intentstatic java.lang.String
TITLE_KEY
Key to retrieve the Title of the message (optional)
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static 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.static 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.static void
appendBatchData(com.google.firebase.messaging.RemoteMessage remoteMessage, 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.static void
dismissNotifications()
Dismiss all notifications shown by the application.
You should call this method afterhave other notifications in your app.
static void
displayNotification(android.content.Context context, android.content.Intent intent)
Call this method to display the notification for this intent.static void
displayNotification(android.content.Context context, android.content.Intent intent, boolean bypassManualMode)
Call this method to display the notification for this intent.static void
displayNotification(android.content.Context context, android.content.Intent intent, BatchNotificationInterceptor interceptor)
Call this method to display the notification for this intent.static void
displayNotification(android.content.Context context, android.content.Intent intent, BatchNotificationInterceptor interceptor, boolean bypassManualMode)
Call this method to display the notification for this intent.static void
displayNotification(android.content.Context context, com.google.firebase.messaging.RemoteMessage remoteMessage)
Call this method to display the notification for this message.static void
displayNotification(android.content.Context context, com.google.firebase.messaging.RemoteMessage remoteMessage, BatchNotificationInterceptor interceptor)
Call this method to display the notification for this message.static BatchNotificationChannelsManager
getChannelsManager()
Get the channels manager, allowing you to tweak how notifications will behave regarding the channels feature introduced in Android 8.0 (API 26)static java.lang.String
getLastKnownPushToken()
Get the last known push token.static java.util.EnumSet<PushNotificationType>
getNotificationsType(android.content.Context context)
Get the enabled notification types
Matches what you've set in setNotificationsType.static boolean
isBatchPush(android.content.Intent intent)
Check if the received push is a Batch one.static boolean
isBatchPush(com.google.firebase.messaging.RemoteMessage message)
Check if the received push is a Batch one.static boolean
isManualDisplayModeActivated()
Get manual display mode for push notifications.static 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.static android.app.PendingIntent
makePendingIntent(android.content.Context context, android.content.Intent intent, com.google.firebase.messaging.RemoteMessage remoteMessage)
Make a PendingIntent suitable for notifications from a given Intent.static 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.static android.app.PendingIntent
makePendingIntentForDeeplink(android.content.Context context, java.lang.String deeplink, com.google.firebase.messaging.RemoteMessage remoteMessage)
Make a PendingIntent suitable for notifications from a given deeplink.static void
onNotificationDisplayed(android.content.Context context, android.content.Intent intent)
Call this method when you just displayed a Batch push notification by yourself.static void
onNotificationDisplayed(android.content.Context context, com.google.firebase.messaging.RemoteMessage remoteMessage)
Call this method when you just displayed a Batch push notification by yourself.static void
refreshRegistration()
Force Batch to renew the push token.static void
requestNotificationPermission(android.content.Context context)
Request the notification runtime permission.static void
setAdditionalIntentFlags(java.lang.Integer flags)
Sets additional intent flags for notifications.static void
setGCMSenderId(java.lang.String gcmSenderId)
Deprecated.Please migrate to FCM: https://batch.com/doc/android/advanced/fcm-migration.htmlstatic void
setLargeIcon(android.graphics.Bitmap largeIcon)
Set a custom large icon that push notifications will use.static void
setManualDisplay(boolean manualDisplay)
Set manual display mode for push notifications.static void
setNotificationInterceptor(BatchNotificationInterceptor interceptor)
Set a notification interceptor.static void
setNotificationsColor(int argbColor)
Set the notification accent color for Lollipop or later.static 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.static void
setSmallIconResourceId(int resourceId)
Set a custom small icon resource that push notifications will use.static void
setSound(android.net.Uri uri)
Set a custom sound uri that push notifications will use.
On Android 8.0, this setting will be applied to the defaultNotificationChannel
that Batch registers, meaning that you won't be able to change it after the first notification.static boolean
shouldDisplayPush(android.content.Context context, android.content.Intent intent)
Should the developer handle and display this push, or will Batch display it? Use this method to know if Batch will ignore this push, and that displaying it is your responsibilitystatic boolean
shouldDisplayPush(android.content.Context context, com.google.firebase.messaging.RemoteMessage remoteMessage)
Should the developer handle and display this push, or will Batch display it? Use this method to know if Batch will ignore this push, and that displaying it is your responsibility
-
-
-
Field Detail
-
ALERT_KEY
public static final java.lang.String ALERT_KEY
Key to retrieve the Alert message- See Also:
- Constant Field Values
-
BODY_KEY
public static final java.lang.String BODY_KEY
Key to retrieve the body of a push message- See Also:
- Constant Field Values
-
PAYLOAD_KEY
public static final java.lang.String PAYLOAD_KEY
Key to retrieve the GCM payload from the activity launch intent- See Also:
- Constant Field Values
-
TITLE_KEY
public static final java.lang.String TITLE_KEY
Key to retrieve the Title of the message (optional)- See Also:
- Constant Field Values
-
-
Method Detail
-
setGCMSenderId
@Deprecated public static void setGCMSenderId(java.lang.String gcmSenderId)
Deprecated.Please migrate to FCM: https://batch.com/doc/android/advanced/fcm-migration.htmlSet the FCM/GCM Sender Id. You can find more info on how to create it in our documentation.- Parameters:
gcmSenderId
- Google API sender ID (for example: 670330094152)
-
setSmallIconResourceId
public static void setSmallIconResourceId(int resourceId)
Set a custom small icon resource that push notifications will use.- Parameters:
resourceId
- id of the resource (for example : R.drawable.push_small_icon)
-
setSound
public static void setSound(android.net.Uri uri)
Set a custom sound uri that push notifications will use.
On Android 8.0, this setting will be applied to the defaultNotificationChannel
that Batch registers, meaning that you won't be able to change it after the first notification. If you use your own channel, this method will have no effect.- Parameters:
uri
- uri of the resource (see Notification.Builder.setSound for more details)
null if you want to use the default notification sound
-
setLargeIcon
public static void setLargeIcon(android.graphics.Bitmap largeIcon)
Set a custom large icon that push notifications will use.- Parameters:
largeIcon
- bitmap of the large icon
-
getChannelsManager
public static BatchNotificationChannelsManager getChannelsManager()
Get the channels manager, allowing you to tweak how notifications will behave regarding the channels feature introduced in Android 8.0 (API 26)
-
dismissNotifications
public static void dismissNotifications()
Dismiss all notifications shown by the application.
You should call this method afterhave other notifications in your app.
-
getNotificationsType
public static 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 static 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.
Note: On Android 8.0 and higher, this method ignores
PushNotificationType#LIGHTS
,PushNotificationType#VIBRATE
andPushNotificationType#SOUND
.
OnlyPushNotificationType#ALERT
will be honored, toggling whether notifications should be displayed or not.
This is because Android 8 manages notifications using channels, meaning that these settings cannot be in your app anymore, and must redirect to the system's UI.
UsePush#getChannelsManager()
to manage your channels.- Parameters:
types
- Type of notifications you want, default = ALERT + LIGHTS + VIBRATE + SOUND
-
isBatchPush
public static 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 theBroadcastReceiver#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 static boolean isBatchPush(com.google.firebase.messaging.RemoteMessage message)
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. If it returns true, you should not handle the push.- Parameters:
message
- Firebase RemoteMessage- Returns:
- true if the push is for Batch and you shouldn't handle it, false otherwise
-
setNotificationsColor
public static 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 inColor
-
isManualDisplayModeActivated
public static boolean isManualDisplayModeActivated()
Get manual display mode for push notifications.
-
setManualDisplay
public static 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
-
-
appendBatchData
public static 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/FCM, that originated this pushopenIntent
- the intent of the notification the will be triggered when the user clicks on it
-
appendBatchData
public static 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 extras of the intent coming from GCM/FCM, that originated this pushopenIntent
- the intent of the notification the will be triggered when the user clicks on it
-
appendBatchData
public static void appendBatchData(com.google.firebase.messaging.RemoteMessage remoteMessage, 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:
remoteMessage
- the FCM message contentopenIntent
- the intent of the notification the will be triggered when the user clicks on it
-
makePendingIntent
public static 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. This is useful for custom receivers, orBatchNotificationInterceptor
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:
context
- Context. Cannot be null.intent
- The intent you want to be triggered when performing the pending intent. Must be an intent compatible withPendingIntent#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. If these extras don't have valid Batch data in it, a valid PendingIntent will still be returned, but some features might not work correctly.- Returns:
- A PendingIntent instance, wrapping the given Intent.
-
makePendingIntent
public static android.app.PendingIntent makePendingIntent(android.content.Context context, android.content.Intent intent, com.google.firebase.messaging.RemoteMessage remoteMessage)
Make a PendingIntent suitable for notifications from a given Intent. This is useful for custom receivers, orBatchNotificationInterceptor
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:
context
- Context. Cannot be null.intent
- The intent you want to be triggered when performing the pending intent. Must be an intent compatible withPendingIntent#getActivity(Context, int, Intent, int)
. Cannot be null.remoteMessage
- Raw Firebase message, used to copy data used by Batch to power features such as direct opens, or mobile landings. Cannot be null. If these extras don't have valid Batch data in it, a valid PendingIntent will still be returned, but some features might not work correctly.- Returns:
- A PendingIntent instance, wrapping the given Intent.
-
makePendingIntentForDeeplink
public static 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. It will use Batch's builtin action activity.This is useful for custom receivers, or
BatchNotificationInterceptor
implementations.- Parameters:
context
- Context. Cannot be null.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. If these extras don't have valid Batch data in it, a valid PendingIntent will still be returned, but some features might not work correctly.- 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
public static android.app.PendingIntent makePendingIntentForDeeplink(android.content.Context context, java.lang.String deeplink, com.google.firebase.messaging.RemoteMessage remoteMessage)
Make a PendingIntent suitable for notifications from a given deeplink. It will use Batch's builtin action activity.This is useful for custom receivers, or
BatchNotificationInterceptor
implementations.- Parameters:
context
- Context. Cannot be null.deeplink
- Deeplink string. Cannot be null.remoteMessage
- Raw Firebase message content, used to copy data used by Batch to power features such as direct opens, or mobile landings. Cannot be null. If these extras don't have valid Batch data in it, a valid PendingIntent will still be returned, but some features might not work correctly.- 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.
-
shouldDisplayPush
public static boolean shouldDisplayPush(android.content.Context context, android.content.Intent intent)
Should the developer handle and display this push, or will Batch display it? Use this method to know if Batch will ignore this push, and that displaying it is your responsibility- Returns:
- true if the push will not be processed by Batch and should be handled, false otherwise
-
shouldDisplayPush
public static boolean shouldDisplayPush(android.content.Context context, com.google.firebase.messaging.RemoteMessage remoteMessage)
Should the developer handle and display this push, or will Batch display it? Use this method to know if Batch will ignore this push, and that displaying it is your responsibility- Parameters:
context
-remoteMessage
- The Firebase message- Returns:
- true if the push will not be processed by Batch and should be handled, false otherwise
-
displayNotification
public static void displayNotification(android.content.Context context, android.content.Intent intent)
Call this method to display the notification for this intent.- Parameters:
context
-intent
-
-
displayNotification
public static void displayNotification(android.content.Context context, android.content.Intent intent, boolean bypassManualMode)
Call this method to display the notification for this intent.- Parameters:
context
-intent
-bypassManualMode
- If true, This method will ignore the manual mode value and always display the notification
-
displayNotification
public static void displayNotification(android.content.Context context, android.content.Intent intent, BatchNotificationInterceptor interceptor)
Call this method to display the notification for this intent. Allows an interceptor to be set for this call, overriding the global one set usingBatch.Push#setNotificationInterceptor(BatchNotificationInterceptor)
- Parameters:
context
-intent
-
-
displayNotification
public static void displayNotification(android.content.Context context, android.content.Intent intent, BatchNotificationInterceptor interceptor, boolean bypassManualMode)
Call this method to display the notification for this intent. Allows an interceptor to be set for this call, overriding the global one set usingBatch.Push#setNotificationInterceptor(BatchNotificationInterceptor)
- Parameters:
context
-intent
-interceptor
-bypassManualMode
- If true, This method will ignore the manual mode value and always display the notification
-
displayNotification
public static void displayNotification(android.content.Context context, com.google.firebase.messaging.RemoteMessage remoteMessage)
Call this method to display the notification for this message.
-
displayNotification
public static void displayNotification(android.content.Context context, com.google.firebase.messaging.RemoteMessage remoteMessage, BatchNotificationInterceptor interceptor)
Call this method to display the notification for this message. Allows an interceptor to be set for this call, overriding the global one set usingBatch.Push#setNotificationInterceptor(BatchNotificationInterceptor)
-
setAdditionalIntentFlags
public static 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.
-
onNotificationDisplayed
public static 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 static void onNotificationDisplayed(android.content.Context context, com.google.firebase.messaging.RemoteMessage remoteMessage)
Call this method when you just displayed a Batch push notification by yourself.- Parameters:
context
-remoteMessage
- The Firebase message
-
getLastKnownPushToken
public static java.lang.String getLastKnownPushToken()
Get the last known push token. The returned token might be outdated and invalid if this method is called too early in your application lifecycle.Batch MUST be started in order to use this method.
- Returns:
- A push token, null if unavailable.
-
setNotificationInterceptor
public static void setNotificationInterceptor(BatchNotificationInterceptor interceptor)
Set a notification interceptor. It allows you to tweak various parts of a notification that Batch generates before displaying it.- Parameters:
interceptor
- ABatchNotificationInterceptor
subclass. Null to remove a previously set one.
-
refreshRegistration
public static void refreshRegistration()
Force Batch to renew the push token. You should not be calling this method unless we told you to.
-
requestNotificationPermission
public static void requestNotificationPermission(android.content.Context context)
Request the notification runtime permission. Android 13 (API 33) introduced a new runtime permission for notifications called POST_NOTIFICATIONS. Without this permission, apps on Android 13 cannot show notifications. This method does nothing on Android 12 and lower, or if your application does not target API 33 or higher.- Parameters:
context
- requesting the permission
-
-