Android > Advanced

Customizing notifications

Setting up custom Push icons

Small notification icon

Small icons appear in the Android notification bar and allow users to recognize your app when they receive a notification. Before releasing a new version of your app on the Store, make sure you've set a custom small icon for your notifications.

Small icon samples

The small icon should be opaque white, using only the alpha channel and 24x24dp as mentioned in Google documentation. You can easily create one using the Android Assets Studio.

Here's how to set it to Batch Push:

public class YourApp extends Application
{
    @Override
    public void onCreate() 
    {
        super.onCreate();

        Batch.setConfig(new Config(YOUR_BATCH_API_KEY));

        Batch.Push.setGCMSenderId("YOUR-GCM-SENDER-ID");
        Batch.Push.setSmallIconResourceId(R.drawable.push_icon);
    }
}

Large notification icon

The large icon is the one that appears on the left of your notification. Here is how it looks: Large icon sample

If you don't set any custom large notification icon, Android will use the small one. Here's how to set a custom large icon to Batch Push:

public class YourApp extends Application
{
    @Override
    public void onCreate() 
    {
        super.onCreate();

        Batch.setConfig(new Config(YOUR_BATCH_API_KEY));

        Batch.Push.setGCMSenderId("your_gcm_sender_id");
        Batch.Push.setSmallIconResourceId(R.drawable.push_icon);
        Batch.Push.setLargeIcon(BitmapFactory.decodeResource(getResources(),
                R.drawable.large_push_icon));
    }
}

Setting notification accent color

Android 5+

On Android Lollipop and Marshmallow, the small icon is displayed on the right of the large icon, in a small colored circle.

Accent color

Android 7+

Starting in Nougat, Google changed the way notifications icons are displayed. The small icon is now displayed in the header area. Android uses the accent color to color the icon, the name of the app and the action buttons.

Accent color

You can customize the color of the circle / name of the app, and Batch provides with an API to do it:

public class YourApp extends Application
{
    @Override
    public void onCreate() 
    {
        ...

        Batch.Push.setNotificationsColor(0xFF00FF00); // You should pass an aRGB integer
    }
}

Setting notification default sound

Starting with Batch 1.8, you can now override the default sound that will be played when showing a notification.
To do so, simply provide an Uri to Batch. Accepted Uris are the same as the framework's Notification.Builder.setSound

public class YourApp extends Application
{
    @Override
    public void onCreate() 
    {
        ...

        Batch.Push.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM));
    }
}

Managing notification display

You can restrict notification display on Android with several parameters such as disabling sound, vibration, or simply disabling notifications for that user if you have a way to ask for opt-in.

Batch Push provides you with an enum with the interactions a notification can have via: PushNotificationType. This enum contains ALERT, SOUND, LIGHTS and VIBRATE. By default, everything is activated.

Disabling notifications

EnumSet<PushNotificationType> set = EnumSet.of(PushNotificationType.NONE); // Disable all notifications

Batch.Push.setNotificationsType(set);

You can call Batch.Push.setNotificationsType whenever you want in the runtime of your application.

Disabling sound

EnumSet<PushNotificationType> set = EnumSet.allOf(PushNotificationType.class);
        set.remove(PushNotificationType.SOUND); // Disable only sound

Batch.Push.setNotificationsType(set);

Please keep in mind that once you've set notification type within Batch, you have to set it again to change it.