Android Customizations

Customizing Android mobile app notifications with your app icons, colors, and style.

🚧

Android Mobile App Notifications Only

This section is for Android Mobile app customizations only. If you have a website, please see our Web Push Customizations guide.

Custom Notification Icons

Read more on the Android Notification Icons page.


Notification Categories

Notification categories are a new Android Oreo (8.0) feature which gives users finer control over notifications. You can select a category from Android Options or API android_channel_id when Sending Push Messages. To learn more about how Android Categories see Android Notification Categories.

2500

Action Buttons

Android 4.1 and newer devices support actions buttons. You can specify up to 3 buttons that will display below your notification content. See Action Buttons.

2500

Big Picture

Android 4.1+ supports a big picture that will show below your notification text when it is expanded. It can be located in your drawable folders, your assets folder in your app, or it can be loaded remotely from a server with a URL and our big_picture API parameter.

The image should be a 2:1 aspect ratio, but your main content should be in 43:24 ratio (~1.79) as some devices crop past this width. Android does not have a size limit, however see our recommended minimum, balanced, and maximum sizes below.

  • Minimum - 512x256
  • Balanced - 1440x720
  • Maximum - 2880x1440

Filetypes jpeg, png, and gif are supported but gifs will be frozen on the first frame until supported by Android.

2500 547

Background Images

Using our latest SDK you can add a background image to all your notifications by adding a image file named onesignal_bgimage_default_image to your res/drawable-xxxhdpi folder.

The size should be 2600x256 (91.4:9) to fit all devices including landscape mode.
(Such as the Samsung Galaxy S7)
In portrait mode the user may only see 1280x256 (5:1) on some devices so do design your image accordingly.

Use onesignal_bgimage_notif_title_color and onesignal_bgimage_notif_body_color in your values/colors.xml to set text colors to match your image.

400

🚧

Important limitations

  1. The small and large icons will be overridden by the background image. Include it as part of your image if you need it to show still.

  2. Big Pictures will not work with Background Images.

  3. Our SDK does not provide an expanded view that supports multiline text. However you can create your own by following Google's Custom View Documentation.

Example color.xml file. Title is set to red and the body is set to green below.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="onesignal_bgimage_notif_title_color">#FFFF0000</color>
    <color name="onesignal_bgimage_notif_body_color">#FF00FF00</color>
</resources>

The image by default will be top left aligned, you may change it to be right aligned by setting the key onesignal_bgimage_notif_image_align to right in your strings.xml.
Example:

<resources>
    <string name="onesignal_bgimage_notif_image_align">right</string>
</resources>

In additional to locally setting the image in your app, it can be with the android_background_layout field through the Create notification REST API call.

The image can be a resource set within the app or an external URL with direct link to the image resource.


LED Color

Certain Android hardware devices have LED notification lights built-in, allowing notifications to trigger a colored notification light on a device upon receipt. Notification colors may be set on a per-message basis in the OneSignal dashboard, or via the OneSignal SDK/API.

Notification colors are set using ARGB Hex values (e.g. a red LED notification light would be in the format FF99000). If LED Color is not set, the light uses the device's default color.


Accent Color

Accent colors only apply to apps targeting Android API level 21+ running on Android 5.0+ devices.

Accent colors are the background color around your small icon, which appears to the left of the notification content in a notification. Like LED Colors, accent colors may be set with an ARGB Hex value in either the dashboard or SDK/API. If Accent Color is not set, the color is set to grey. Read more in Android Notification Icons


Notification Grouping

Android supports grouping or combining notifications together.

🚧

Behavior changes

  • Manually setting the group only works on Android 6 and lower.
  • Android 7.0+ will automatically group your notifications after the device has 4 or more visible notifications for your app, even if you don't set a group key.
  • Android 7.0+ automatically generates the text for the summary notification for the grouped notifications.
    The custom group message only shows on Android 6.0 (Marshmallow) devices and older.

For Android 7+ you can setup your Android NotificationExtenderService to group messages and add another NotificationExtenderService to update the summary notification. See Android's Group Notify Guide for more details.

Note there are some limitations that Android 7+ has for these summary notifications. You can only modify the text, accent color and small icon (not large icon). However, you can still modify the children.

For Android 6 and lower. Simply enter any value in the “Group Key” field under the Android Options when Sending Push Messages. This is the android_group parameter on the REST API. Notifications with the same group key will automatically group on the device.

900
  • Also works on Amazon devices, set the group key listed under the amazon settings as well.

App Icon Badge Counts

The OneSignal SDK automatically sets the badge count on your app to the number of notifications that are currently in the notification shade. If you want to disable this you can add the following to your AndroidManifest.xml.

See our Android Badges Guide for more details.


Notification Sounds

Read more in Customize Notification Sounds


Background Data and Notification Overriding

OneSignal supports sending additional data along with a notification as key value pairs. You can read this additional data when a notification is opened by adding a setNotificationOpenedHandler instead.

However, if you want to one of the following...

  • Receive data in the background with or without displaying a notification.
  • Override specific notification settings depending on client-side app logic such as custom accent color, vibration pattern, or other any other NotificationCompat options available. See Android's documentation on the NotificationCompat options.

...continue with the instructions in our Service Extensions Setup.


Resume last Activity when opening a Notification

Add the following code to the top of onCreate in your launcher Activity.

private static boolean activityStarted;

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  if (   activityStarted
      && getIntent() != null
      && (getIntent().getFlags() & Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) != 0) {
    finish();
    return;
  }
  
  activityStarted = true;
}

Additional information:
By default OneSignal calls startActivity with the following intent flags.

Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK

Changing the open action of a notification

By default OneSignal will open or resume your launcher Activity when a notification is tapped on. You can disable this behavior by adding the meta-data tag com.onesignal.NotificationOpened.DEFAULT set to DISABLE inside your application tag in your AndroidManifest.xml.

<application ...>
   <meta-data android:name="com.onesignal.NotificationOpened.DEFAULT" android:value="DISABLE" />
</application>

Make sure you are initializing OneSignal with setNotificationOpenedHandler in the onCreate method in your Application class. You will need to call startActivity from this callback. See example setNotificationOpenedHandler method.

🚧

This disables the Launch URL

This will stop the OneSignal Launch URL from opening a URL in an in-app browser. You will need to open URLs with your own webview.

Preventing Multiple Instances of the same Activity

To prevent more than one copy of your Activity from running add android:launchMode="singleTask" to your Activity in your AndroidManifest.xml.

<activity
          android:name=".MainActivity"
          android:label="OneSignal Example"
          android:launchMode="singleTask" />

Right-to-Left (RTL) Notification Support

To support notifications with right-to-left languages correctly you must add android:supportsRtl="true" to your <application> tag in your AndroidManifest.xml.

<application
             android:supportsRtl="true"
             android:icon="@drawable/ic_launcher"
             android:theme="@style/AppTheme"
             android:label="OneSignal Example"
             android:name=".OneSignalExampleApp">
     ...
  </application>

Note, make sure to test all your Activities as this effect all views in your app.


Example Project

We have an example project with a custom sound, small icon, and large icon you can try for reference.


Android SDK API Reference

See our Android Native SDK reference for more information.


What’s Next

Learn about setting up more features, or start using the OneSignal Dashboard