Configure notification preferences

You can change the following notification preferences:

  • notification channel in Android O (and later)
  • sound
  • vibration
  • icons
  • light
  • flags

Setting notification channels in Android O (and later)

To set a notification channel in Android O, call the following method in the NotificationsPreference API:
public void setNotificationChannelId(Context context, String channelId)

where channelId is one of the application’s notification channels.

Note: When you use notification channels in Android O, the following notification preferences can be overridden by the channel:

  • priority
  • sound
  • lights
  • vibration

Enabling and changing sound notifications

To play a sound for your mobile app messages, you must modify the NotificationsPreference class.

  1. To enable sound for notifications, call the following static method from the NotificationsPreference class:
    NotificationsPreference.setSoundEnabled(context, true);

  2. To change the notifications sound, first add your sound file to /res/raw/ folder in your project, and then call the static method NotificationsPreference.setSound(context,soundResourceID).

For example:

NotificationsPreference.setSound(context, R.raw.notification_sound)

Remember: If you enabled sound but did not set a custom sound, the system default sound is used.

Enabling and changing vibration notifications

To enable or change vibrations for your mobile app messages, you must modify AndroidManifest.xml and the NotificationsPreference class.

  1. To enable vibration for notifications, add the following permission to your AndroidManifest.xml file:

  2. Then, call the following static method from the NotificationsPreference class:
    NotificationsPreference.setVibrateEnabled(context, true);

  3. To change the notifications vibration pattern, call the static method
    NotificationsPreference.setVibrationPattern(context,vibrationPattern)

    For example:
    
long [] vibrate = {0,100,200,300};
    NotificationsPreference.setVibrationPattern(context,vibrate);

Remember: If you enabled vibration but you did not set a custom vibration pattern, the system default vibration pattern is used.

Enabling and changing icon notifications

To change the notification (small) icon, call the setIcon method in NotificationPreferences with the context and resource ID:

For example:

MceSdk.getNotificationsClient().getNotificationsPreference().setIcon(
        getApplicationContext(), (iconId));

Remember: The default notifications icon is android.R.drawable.sym_def_app_icon.

If you want to use the notification large icon, you must also set the setLargeIcon method in the NotificationPreferences class.

For example:

MceSdk.getNotificationsClient().getNotificationsPreference().setLargeIcon(
        getApplicationContext(), (largeIconId));

Enabling and changing light notifications

To enable or change light notifications for your mobile app messages, you must modify the NotificationsPreference class.

  1. To enable notifications lights, call the following static method from the NotificationsPreference class.
    NotificationsPreference.setLightsEnabled(context, true);

  2. To change the notifications lights preferences, call the static method NotificationsPreference.setLights(getApplicationContext(), new int[] { ledARGB , ledOnMS , ledOffMS });.

For example:

int ledARGB = 0x00a2ff;
        int ledOnMS = 300;
        int ledOffMS = 1000:
        NotificationsPreference.setLights(getApplicationContext(), new int[] { ledARGB, ledOnMS, ledOffMS });

Important: If you pass null to any of the setter methods in the NotificationsPreference, the preference resets, and the default value is applied for new notifications.

Enabling and changing flag notifications

To enable or change flag notifications for your mobile app messages, you must modify the NotificationsPreference class.

  1. To add notification flags for notifications, call the static method NotificationsPreference.addFlags(context, NOTIFICATION_FLAG_1 | NOTIFICATION_FLAG_2);.

For example:

NotificationsPreference.addFlags(context, Intent.FLAG_ACTIVITY_SINGLE_TOP);

Note: The default notifications flags are FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_CLEAR_TOP.

All the flags are combined with FLAG_ACTIVITY_NEW_TASK

For more information about flags, see Android Developer FLAG_ACTIVITY_MULTIPLE_TASK .