Skip to content

Notification settings

Stanislav Slavin edited this page Apr 24, 2018 · 19 revisions

Mobile Messaging supports configuration of Notifications provided by the library. Different Notification settings are available via NotificationSettings.Builder.

Configure Notification Settings

Callback Activity

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.

new NotificationSettings.Builder(context)
.withCallbackActivity(MyActivity.class)
.build();

Notification Title

Default notification title is application name (R.string.app_name). However custom notification title can also be used in notifications.

new NotificationSettings.Builder(this)
.withDefaultTitle("MyCustomNotificationTitle")
.build();

Notification Icon

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://developer.android.com/guide/practices/ui_guidelines/icon_design_status_bar.html

new NotificationSettings.Builder(this)
.withDefaultIcon(R.drawable.ic_my_notification_icon)
.build();

Multiple notifications

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.

new NotificationSettings.Builder(this)
.withMultipleNotifications()
.build();

Intent Flags

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.

new NotificationSettings.Builder(this)
.withIntentFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
.build();

Pending Intent Flags

It is also possible to set pending intent flags. The flags are delegated to PendingIntent.getActivity(). Default flag is PendingIntent.FLAG_CANCEL_CURRENT.

new NotificationSettings.Builder(this)
.withPendingIntentFlags(0)
.build();

Notification Auto-cancel

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().

new NotificationSettings.Builder(this)
.withNotificationAutoCancel()
.build();

...

new NotificationSettings.Builder(this)
.withoutNotificationAutoCancel()
.build();

Foreground Notifications

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.

new NotificationSettings.Builder(this)
.withoutForegroundNotification()
.build();

Heads-up notifications

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.

new NotificationSettings.Builder(this)
.withoutHeadsUpNotifications()
.build();

Set Notification Settings

Constructed Notification Settings can be applied via MobileMessaging.Builder.

MobileMessaging mobileMessaging = new MobileMessaging.Builder(application)
                .withDisplayNotification(new NotificationSettings.Builder(application)
                    .withoutNotificationAutoCancel()
                    .withoutForegroundNotification()
                    .build())
                .build();

Mobile Messaging library can also be configured to work without notifications.

MobileMessaging mobileMessaging = new MobileMessaging.Builder(application)
                .withoutDisplayNotification()
                .build();
Clone this wiki locally