Android Mobile Notifications With Unity

In this tutorial, you’ll learn about Unity’s Mobile Notifications and how to create and schedule your very own notifications for a Unity app running on an Android device. By JJ Richards.

Leave a rating/review
Download materials
Save for later
Share

Ding! Time to wake up.
Ding! You have an appointment in 30 minutes.
Ding! Tomorrow is your mother’s birthday.

Notifications are a common and valuable part of modern life, so it’s natural to expect your favorite mobile apps and games to use them too. In this tutorial, you’ll learn about Unity’s Mobile Notifications and how to create and schedule your very own notifications for a Unity app running on an Android device. Notifications will take your apps to the next level, helping you to retain user attention and also to keep your users informed.

Notifications on an Android device

Note: This tutorial assumes you know the basics of Android development in Unity. If you are new to the subject, check out our Unity for Beginners series first. For this tutorial, you’ll need Unity 2019.3.0f3 or later. Make sure you’ve installed Android build support as well.

Getting Started

Download the project by clicking the Download Materials button at the top or bottom of the tutorial.

Open the starter project and look at the folder structure in the Project window.

Folder setup in the Project window

In Assets ► RW, you’ll find everything you need for the project:

  1. Scenes: Contains the NotificationTutorial scene.
  2. Scripts: Empty folder for the script you’ll create.
  3. Textures: Contains sample art for you to use.
  4. Prefabs: A sample interface for you to use.

Take a quick look at the NotificationTutorial scene in the Scenes folder. You’ll notice that it’s just an empty scene with nothing much going on. It represents a typical Unity app with no Notification capabilities. In the steps to follow, you’ll be adding some basic UI elements, you’ll also be adding the required components and scripts to enable this Unity app to send Notifications.

Now you’re ready to start getting noticed! :]

Setting the Scene

Since this is an Android tutorial, make sure you select Android as the platform in your Build Settings. Open the Package Manager and you’ll see that TextMeshPro and Mobile Notifications are already imported.

The Package Manager's setup

Open the NotificationTutorial scene inside the Scenes folder. You’ll find a very basic scene with a camera, a Screen Overlay Canvas and an EventSystem. Set your Game view to Portrait to match the default orientation configured in Project Settings ► Player.

Start by creating a title for the main page. Select Canvas in the Hierarchy, add a UI ► Text – TextMeshPro GameObject and call it Title. Give the text field a catchy name: Notation Tutorial.

Create an empty GameObject under Canvas to hold some buttons. Call it ButtonGroup and add a Horizontal Layout Group component to adjust the layout as you like. You can also adjust the RectTransform to suit your preferences.

Next, create two buttons by selecting ButtonGroup in the Hierarchy and then right-clicking to select UI ► Button-TextMeshPro.

You’ll use the first button to send a single notification after a short delay, so name it ShortNote. Set the Text to Notify in 10 seconds.

You’ll use the second button to schedule a single notification after a long delay, so name it LongNote. Set the Text to Notify in one minute.

If you don’t want to set this up yourself, there’s a prefab ready to import in RW ► Prefabs.

Notifications Tutorial with two buttons set up

The UI is now complete. Before implementing specific notifications, take a moment to consider why notifications are important for your app.

Using Notifications to Improve Retention

One of the primary benefits of notifications is the positive impact they have on player retention. Notifications help bring players back to a game they haven’t played in a while. These player lapses are often addressed on a 3-day, 7-day or 30-day cycle from the player’s last active session.

Notifications help players start a session at the right time via timers and alerts related to gameplay events. For example, you might notify players when the smithy has finished their brand new sword or their castle is under attack.

You can also use notifications to improve retention by alerting players about scheduled events and tournaments, whether created by the developer or other players.

All these examples are compelling reasons for a player to come back to a game, and notifications are a great way to remind players about those reasons.

Understanding Notifications

The notification itself has five parts that you’ll need to create and provide:

  1. Title: A short, bolded text.
  2. Description: A longer, non-bolded text.
  3. Small icon: A small, pure white icon that appears throughout the device UI.
  4. Large icon: A large, colored icon that only appears when space in the UI is available.
  5. Delivery date: The date and time when the app should notify the user.

As the app developer, you don’t control the device UI or how the user interacts with the notification – that’s the job of the device OS. Your job is to supply all five parts of the notification so the device OS can properly send the message according to a variety of user scenarios.

Now that you have an idea of the structure behind the notifications, it’s time to get your assets ready to go.

Prepping Assets

To have the best effect, your notifications shouldn’t only be timely, they should also be attractive. For that, you’ll need some artwork.

Unity’s Mobile Notifications Package provides an easy way to manage the art assets you need to create for notifications. This tutorial uses Mobile Notifications Package preview.5 – 1.0.4 from Unity’s Package Manager. You can find the Mobile Notifications Settings under Project Settings.

Your first step is to set up three icons:

  1. For Identifier icon-0 with Type Small Icon, select the icon_timer asset.
  2. Next, for Identifier icon_1, which has Type Large Icon, select the RW_Icon_macOS_256 asset.
  3. Finally, for Identifier alarm, with Type Small Icon, select the icon_notification_bell asset.

These identifiers need to match the script that you’ll create next. The settings dialog should look like this:

Mobile Notifications Settings screen

The scene also needs a way to process notifications.

To set these up, create an empty GameObject called NotificationManager. The scene hierarchy should now look like this:

Current screen hierarchy

Select that GameObject and add a Game Notifications Manager component, which comes with the Mobile Notifications Package.

Inside Scripts, create a new C# script named NotificationManager. Attach that script to the NotificationManager GameObject as well.

Notifications Manager setup

Now that all the pieces are in place, it is time to connect them.

JJ Richards

Contributors

JJ Richards

Author

Gijs Bannenberg

Tech Editor

Sandra Grauschopf

Editor

Chris Language

Final Pass Editor

Over 300 content creators. Join our team.