Notification Builder

On Android, the TUNE SDK provides a TuneNotificationBuilder class that lets you customize the appearance and behavior of the push notifications from TUNE.


Before creating a TuneNotificationBuilder object, make sure you have created your channel so you can pass in the channel ID. For more information, please see Creating a Notification Channel.

Once you've created your channel, create a TuneNotificationBuilder object passing in a resource id to an icon, as well as passing in your channel ID.

TuneNotificationBuilder builder = new 
TuneNotificationBuilder(R.drawable.your_icon, YOUR_CHANNEL_ID);

If you support versions before and after Lollipop, you may want to use different icons depending on the version. Starting from Lollipop, push notifications only display the alpha of the icon on a gray background.

In such a case you can do:

int smallIcon;
    smallIcon = R.drawable.your_alpha_icon;
} else {
    smallIcon = R.drawable.your_icon;
TuneNotificationBuilder builder = new TuneNotificationBuilder(smallIcon, YOUR_CHANNEL_ID);

Finally, tell the TUNE SDK to use the builder you've created. This call should go after Tune.init:


You're set! Any TUNE push notifications you receive in your app will use this builder to display the notification.


Aside from the icon, the TuneNotificationBuilder also allows you to customize the following fields:


Sets the large icon that is shown in TUNE push notifications.

This is only visible when the user expands the tray and will replace the small icon. However, on APIs before Lollipop, the small icon is still displayed on the far right of the notification. On later APIs, the small icon is super imposed at the bottom right of the large icon.



Sets the group that TUNE notifications should be a part of. Grouped notifications may display in a cluster or stack on devices which support such rendering.

Grouping is only supported on devices running Android KitKat and newer.



Sets the accent color for TUNE push notifications.

Color is only displayed on devices running Lollipop and newer.



Sets the visibility level for TUNE push notifications.

Visibility level is one of VISIBILITY_PRIVATE (the default), VISIBILITY_PUBLIC, or VISIBILITY_SECRET.

Visibility is only supported on devices running Lollipop and newer.



Sets the sound to be played when a TUNE push notification is received. If not set, the default system sound will be used.

Will override setNoSound if called after.

// Set the sound from a raw sound file in your project
builder.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.your_sound_file));


Sets the vibration pattern to be played when a TUNE push notification is received. If not set, the default system vibrate pattern will be used.

Will override setNoVibrate if called after.

This method requires your AndroidManifest.xml to hold the permission VIBRATE:

<uses-permission android:name="android.permission.VIBRATE" />

Pass in an array of longs that are the durations for which to turn on or off the vibrate in milliseconds.

  • The first value indicates the number of milliseconds to wait before turning the vibrate on.
  • The next value indicates the number of milliseconds to keep the vibrate on before turning it off.
  • Subsequent values alternate between durations in milliseconds to turn the vibrate off or on.
// Vibrate with 0 delay for 2s, then stop for 1s, then vibrate 1s, then stop 1s
builder.setVibrate(new long[]{0, 2000, 1000, 1000, 1000});


Sets the only alert once setting for TUNE push notifications.

For notifications with sound and vibration set, this setting determines whether the sound and vibration get played every time, or only once if the notification is already showing.

If set to true, then receiving another TUNE push notification while one is showing will not play the sound and vibration again.



Sets that no sound should be played when a TUNE push notification is received.

Will override setSound if called after.



Sets that no vibration should be played when a TUNE push notification is received.

Will override setVibrate if called after.


No Comments

Leave a reply