-
Notifications
You must be signed in to change notification settings - Fork 17
Notification settings
Mobile Messaging supports configuration of Notifications provided by the library. Different Notification settings are available via NotificationSettings.Builder.
It is possible to define custom callback activity to open when user taps on notification. By default the library will use default activity for the application package.
NotificationSettings.Builder(context)
.withCallbackActivity(MyActivity::class.java)
.build()
expand to see Java code
new NotificationSettings.Builder(context)
.withCallbackActivity(MyActivity.class)
.build();
Default notification title is application name (R.string.app_name). However custom notification title can also be used in notifications.
NotificationSettings.Builder(this)
.withDefaultTitle("MyCustomNotificationTitle")
.build()
expand to see Java code
new NotificationSettings.Builder(this)
.withDefaultTitle("MyCustomNotificationTitle")
.build();
To force custom title and message body for In-App chat notifications please read Customize notifications
Default notification icon is launcher icon (R.mipmap.ic_launcher). Custom icon resource id can also be supplied to overwrite default behavior. If supplied, the icon should follow guidelines described here: https://m2.material.io/design/iconography/system-icons.html#design-principles
NotificationSettings.Builder(this)
.withDefaultIcon(R.drawable.ic_my_notification_icon)
.build()
expand to see Java code
new NotificationSettings.Builder(this)
.withDefaultIcon(R.drawable.ic_my_notification_icon)
.build();
Option for setting notification accent color is available since Android 6, API level 23.
NotificationSettings.Builder(this)
.withColor(ContextCompat.getColor(this, R.color.red))
.build()
expand to see Java code
new NotificationSettings.Builder(this)
.withColor(ContextCompat.getColor(this, R.color.red))
.build();
It is possible to show multiple notifications in status bar through NotificationSettings.Builder
. By default, when new notification arrives, it shows single notification which is overwritten by the new one.
NotificationSettings.Builder(this)
.withMultipleNotifications()
.build()
expand to see Java code
new NotificationSettings.Builder(this)
.withMultipleNotifications()
.build();
It is possible to configure notification intent flags. Provided flags are delegated to Intent.addFlags(). Default flags are Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP.
NotificationSettings.Builder(this)
.withIntentFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
.build()
expand to see Java code
new NotificationSettings.Builder(this)
.withIntentFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
.build();
It is also possible to set pending intent flags. The flags are delegated to PendingIntent.getActivity(). Default flag is PendingIntent.FLAG_CANCEL_CURRENT.
NotificationSettings.Builder(this)
.withPendingIntentFlags(0)
.build()
expand to see Java code
new NotificationSettings.Builder(this)
.withPendingIntentFlags(0)
.build();
Notification auto-cancel parameter can be set via Notification Settings by calling an appropriate Builder method. The default value of auto-cancel is true. This parameter is forwarded to NotificationCompat.Builder.setAutoCancel().
NotificationSettings.Builder(this)
.withNotificationAutoCancel()
.build()
...
NotificationSettings.Builder(this)
.withoutNotificationAutoCancel()
.build()
expand to see Java code
new NotificationSettings.Builder(this)
.withNotificationAutoCancel()
.build();
...
new NotificationSettings.Builder(this)
.withoutNotificationAutoCancel()
.build();
It is possible to configure library to not show notifications when your application is running in foreground. By default the library will show notifications always.
NotificationSettings.Builder(this)
.withoutForegroundNotification()
.build()
expand to see Java code
new NotificationSettings.Builder(this)
.withoutForegroundNotification()
.build();
By default SDK will show Heads-up notifications on devices running Android 5.0+. Such notifications will only be shown when the app is in background or killed. You can disable heads-up notifications using method described below.
NotificationSettings.Builder(this)
.withoutHeadsUpNotifications()
.build()
expand to see Java code
new NotificationSettings.Builder(this)
.withoutHeadsUpNotifications()
.build();
By default SDK will show Modal mirror push notifications. You can disable modal mirror push notifications using method described below.
NotificationSettings.Builder(this)
.withoutModalInAppNotifications()
.build()
expand to see Java code
new NotificationSettings.Builder(this)
.withoutModalInAppNotifications()
.build();
Constructed Notification Settings can be applied via MobileMessaging.Builder.
val mobileMessaging = MobileMessaging.Builder(application)
.withDisplayNotification(NotificationSettings.Builder(application)
.withoutNotificationAutoCancel()
.withoutForegroundNotification()
.build())
.build()
expand to see Java code
MobileMessaging mobileMessaging = new MobileMessaging.Builder(application)
.withDisplayNotification(new NotificationSettings.Builder(application)
.withoutNotificationAutoCancel()
.withoutForegroundNotification()
.build())
.build();
val mobileMessaging = MobileMessaging.Builder(application)
.withoutDisplayNotification()
.build()
expand to see Java code
MobileMessaging mobileMessaging = new MobileMessaging.Builder(application)
.withoutDisplayNotification()
.build();
If you have any questions or suggestions, feel free to send an email to [email protected] or create an issue.
- Library events
- Server errors
- Users and installations
- Messages and notifications management
- Inbox
Geofencing API- DEPRECATED- Android Manifest components
- Privacy settings
- In-app chat
- Infobip RTC calls and UI
- Backup rules