Batch SDK v3 is a major release, which introduces breaking changes from 2.x. This guide describes how to update your application when using a previous version.
If your application is still using Batch SDK v1 please follow our migration guide from V1 beforehand.
Upgrading the SDK version
To upgrade from v2 to v3, you need to change the SDK version in your build.gradle:
Batch now uses Kotlin (1.9.0) internally. This should not affect your existing Java-based integrations as public APIs remain in Java. However, be aware of this change if you are inspecting the SDK's internals or if you encounter any unexpected behavior related to Kotlin interoperability.
Push migration
Managing notification display
Methods setNotificationsType and getNotificationsType in Batch.Push have been removed.
Please replace their usage with the following methods:
Batch.Push.setShowNotifications(show: boolean): Use this to control whether Batch should display push notifications.
Batch.Push.shouldShowNotifications(): Use this to check if Batch is configured to show push notifications.
Batch will preserve your previous settings, and shouldShowNotifications() will reflect them.
So, if you were doing something like this in your application :
// Disable notifications
val set = EnumSet.of(PushNotificationType.NONE)
Batch.Push.setNotificationsType(set)
// or
// Enable notifications
val set = EnumSet.allOf(PushNotificationType::class.java)
set.remove(PushNotificationType.NONE)
Batch.Push.setNotificationsType(set)
// Disable notifications
EnumSet<PushNotificationType> set = EnumSet.of(PushNotificationType.NONE);
// or
// Enable notifications
EnumSet<PushNotificationType> set = EnumSet.allOf(PushNotificationType.class);
set.remove(PushNotificationType.NONE);-
Batch.Push.setNotificationsType(set);
You should now do:
// Disable notifications
Batch.Push.setShowNotifications(false)
// or
// Enable notifications
Batch.Push.setShowNotifications(true)
// Disable notifications
Batch.Push.setShowNotifications(false);
// or
// Enable notifications
Batch.Push.setShowNotifications(true);
Batch SDK v3 adds compatibility for Mobile Landings with Push v2 which can be created from the Batch Dashboard's drag & drop composer.
In-App Message Interception
The interface Batch.Messaging.LifecycleListener2 has been removed. Please replace its usage with the new Batch.Messaging.InAppInterceptor interface.
Use the method Batch.Messaging.setInAppInterceptor(Batch.Messaging.InAppInterceptor interceptor) to set your custom interceptor.
So if you were doing:
class SampleApplication : Application(), LifecycleListener2 {
override fun onCreate() {
super.onCreate()
// [...]
Batch.Messaging.setLifecycleListener(this)
}
override fun onBatchInAppMessageReady(message: BatchInAppMessage): Boolean {
// Your implementation
}
}
public class SampleApplication extends Application implements LifecycleListener2 {
@Override
public void onCreate() {
super.onCreate();
Batch.Messaging.setLifecycleListener(this);
}
@Override
public boolean onBatchInAppMessageReady(@NonNull BatchInAppMessage message) {
// Your implementation
}
}
You should now do:
class SampleApplication : Application(), InAppInterceptor {
override fun onCreate() {
super.onCreate()
// [...]
Batch.Messaging.setInAppInterceptor(this)
}
override fun onBatchInAppMessageReady(message: BatchInAppMessage): Boolean {
// Your custom implementation
}
}
public class SampleApplication extends Application implements InAppInterceptor {
@Override
public void onCreate() {
super.onCreate();
Batch.Messaging.setInAppInterceptor(this);
}
@Override
public boolean onBatchInAppMessageReady(@NonNull BatchInAppMessage message) {
// Your implementation
}
}
For more information, please see the In-App messaging manual mode section.
Messaging Lifecycle Listener
The following methods in Batch.Messaging.LifecycleListener have been removed:
onBatchMessageCancelledByAutoclose
onBatchMessageCancelledByUser
onBatchMessageCancelledByError
onBatchMessageWebViewActionTriggered
Please update your implementation to use the new onBatchMessageClosed(String messageIdentifier, MessagingCloseReason reason) method. The new MessagingCloseReason enum will provide the context about why the message was closed.
WebView actions will now trigger the updated onBatchMessageActionTriggered method, with the analyticsID of the action being passed as the ctaIdentifier.
The index (Int) parameter in onBatchMessageActionTriggered has been replaced by ctaIdentifier (String). The method signature is now: