Class BatchNotificationChannelsManager
- java.lang.Object
-
- com.batch.android.BatchNotificationChannelsManager
-
public final class BatchNotificationChannelsManager extends java.lang.ObjectBatchNotificationChannelsManager manages how Batch interacts with Android 8.0 (API 26). It allows you to control which default notification channel Batch will use, how it is named, or to provide your own channel per notification
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceBatchNotificationChannelsManager.ChannelNameProviderInterface describing a channel name provider.static interfaceBatchNotificationChannelsManager.NotificationChannelIdInterceptorInterface describing a channel ID interceptor for notifications displayed by Batchstatic classBatchNotificationChannelsManager.StringResChannelNameProviderImplementation ofBatchNotificationChannelsManager.ChannelNameProviderusing a String resource to automatically fetch the right translation.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_CHANNEL_ID
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static booleanopenSystemChannelSettings(android.content.Context context)Opens the notification channel settings system UI for Batch's default channel.static booleanopenSystemChannelSettings(android.content.Context context, java.lang.String channelId)Opens the notification channel settings system UI for the specified channelstatic BatchNotificationChannelsManagerprovide()voidsetChannelIdInterceptor(BatchNotificationChannelsManager.NotificationChannelIdInterceptor interceptor)Used to set a channel id interceptor, allowing you to override the Channel ID of a notification, per notification.
You will be called on this interceptor before displaying notifications, unless you're in manual mode and don't use Batch to display the notification.voidsetChannelIdOverride(java.lang.String channelId)Overrides the default notification channel that Batch will use for notifications.
By default, Batch will manage its own channel, identified byDEFAULT_CHANNEL_ID.
After calling this method with a non-null channelId, Batch will stop trying to register its default channelvoidsetChannelName(android.content.Context context, int channelNameResourceId)Used to set a channel name provider, allowing you to change Batch's default channel name.voidsetChannelNameProvider(BatchNotificationChannelsManager.ChannelNameProvider provider)Used to set a channel name provider, allowing you to change Batch's default channel name.
-
-
-
Field Detail
-
DEFAULT_CHANNEL_ID
public static final java.lang.String DEFAULT_CHANNEL_ID
- See Also:
- Constant Field Values
-
-
Method Detail
-
provide
public static BatchNotificationChannelsManager provide()
-
setChannelIdOverride
public void setChannelIdOverride(@Nullable java.lang.String channelId)Overrides the default notification channel that Batch will use for notifications.
By default, Batch will manage its own channel, identified byDEFAULT_CHANNEL_ID.
After calling this method with a non-null channelId, Batch will stop trying to register its default channelNote: Please make sure that you've registered this channel using
NotificationManager.createNotificationChannel(NotificationChannel)orNotificationManager.createNotificationChannelGroup(NotificationChannelGroup)
Set to 'null' to revert to the default channel.
-
setChannelNameProvider
public void setChannelNameProvider(@Nullable BatchNotificationChannelsManager.ChannelNameProvider provider)Used to set a channel name provider, allowing you to change Batch's default channel name.
This is the string that the user will see in their device settings, so you should translate it.
Batch will call you back on your provider at least once, to get the channel name, and then will call you on every locale change, to make sure that the Android OS has the right translation.
If your provider throws an exception, Batch will use its default name.
If you simply want to use a string resource, use
setChannelName(Context, int).
Set to 'null' to remove the provider and use Batch's default one.
-
setChannelName
public void setChannelName(@NonNull android.content.Context context, @StringRes int channelNameResourceId)Used to set a channel name provider, allowing you to change Batch's default channel name.
This is the string that the user will see in their device settings, so you should translate it properly.
Calling this is the equivalent of callingsetChannelNameProvider(ChannelNameProvider)with aBatchNotificationChannelsManager.StringResChannelNameProviderinstance.
Calling this method will remove any provider set with
setChannelNameProvider(ChannelNameProvider)
-
setChannelIdInterceptor
public void setChannelIdInterceptor(@Nullable BatchNotificationChannelsManager.NotificationChannelIdInterceptor interceptor)Used to set a channel id interceptor, allowing you to override the Channel ID of a notification, per notification.
You will be called on this interceptor before displaying notifications, unless you're in manual mode and don't use Batch to display the notification.
The provider might be called on ANY API Level
If your provider throws an exception, Batch will use its default name.
-
openSystemChannelSettings
public static boolean openSystemChannelSettings(@NonNull android.content.Context context)Opens the notification channel settings system UI for Batch's default channel.Will do nothing on API < 26
- Parameters:
context- Your context- Returns:
- Whether the system settings have been opened or not. Always false on API < 26
-
openSystemChannelSettings
public static boolean openSystemChannelSettings(@NonNull android.content.Context context, @NonNull java.lang.String channelId)Opens the notification channel settings system UI for the specified channelWill do nothing on API < 26
- Parameters:
context- Your context. Can't be null.channelId- The channel to open this. Can't be null.- Returns:
- Whether the system settings have been opened or not. Always false on API < 26
-
-