Some Best Practices in Using Android Notification
By: Kayvan Kaseb
Tags: Android App Development, Android Notification, Android Apps, Notifications, Android

The picture is provided by Unsplash

Basically, Android notification provides information for users, and it can be an effective way for communicating with them as well. Besides, Android notifications become visible to users in various locations and formats, such as an icon in the status bar, a more detailed entry in the notification drawer, a badge on the app’s icon, and on paired wearables in a self-directing way. This article aims to discuss some advanced features and best practices in using Android notification.

Introduction and Overview

A notification is a message, which you can be able to show to the user outside of your application’s normal UI. Notifications appear in the phone’s notification area, and then can be expanded to see more information. In general, this is used to keep the user informed about events that are coming in, such as new email messages, new chat messages, or even an upcoming calendar event. Notifications can consists of actions that let the user take a relevant action from within the notification drawer. At the minimum level, all notifications include a base layout including:

Icon of the app or relevant user image Title and message Timestamp.

However, a notification can be included some basic details as follows:

a notification with basic details, the picture is provided by Google documents

Small icon: This is required and set with setSmallIcon() . App name: This is supported by the system. Time stamp: This is provided by the system, but you can override with setWhen() or hide it with setShowWhen(false) . Large icon: This is optional, and it usually used just only for contact photos and set with setLargeIcon() . Title: This is optional, and can be set with setContentTitle() . Text: This is optional, and can be set with setContentText() .

As you noticed, Android notification provides information for users, and it can also be an effective way for communicating with them. However, there are some tips for using notifications because it would be harmful experience for users in some inappropriate cases. Therefore, the following sections of this essay will consider some new features and best practices in using Android notifications.

Some general tips for using Android notification

Respecting to user’s settings: If they have communicated to you in your Android app that they want a certain setting for your notifications, you should respect that decision as a developer. This means you do not try to override and ignore it. So, you should check the notifications that are not blocked by those users. Sending well-structured notification: You should use well-structured notifications in your Android app by utilizing style, such as MessagingStyle, InboxStyle, and BigPictureStyle. Sending relevant and timely notification: You should make sure that your notifications are relevant and timely. For instance, using high priority FCM messages to ensure that the user gets the notification when you intend them to get your notification. So, you should prioritize posting the notifications at first, and then you should make change the appearance to better one as much as possible. You should not annoy your users: When you want to post a notification to the users, you should use alert once. Also, you should make sure that they are not getting buzzed. In short, you have to respect the user. Otherwise, they might just turn off your notifications, and then you have got no way of communicating to them. Probably, this leads to uninstall your app, which would be far worse. Sending actionable notification: The point of notifications is that they are created there to be used efficiently. By definition, the user wants to inform something, which means they typically require to do something. Thus, you must not send them a notification that just only tells them, for example, we sync some issues in the background. This is not the best use of notifications at all. Synchronizing across the Android devices: If you aware of that your user uses your app on multiple Android devices such as tablets and desktops, you should try and synchronize notifications that they dismiss on one or read on one across others.

Notification Channels

Notification channel is a fine grained notification control for users with a consistent setting UI to users. Starting in Android 8.0 (API level 26), all notifications have to be assigned to a channel. For example, I have just got a new notification about a friend following me, I can long press, and I see that I have the option to turn off the follower’s channel or take a look at all of the channels. As a result, users can be able to change these settings, and decide which notification channels from your app should be interrupting or visible. In addition, notification channels, which are also called notification categories in the UI, are collections of associated notifications.

Another significant point is that you can be able to separate the channels, or you can organize notification channels into channel groups. Channel groups let you group notification channels together in the UI. For instance, you can have a channel group for your work account notifications and for your personal account notifications. To set up a channel, first of all, you simply create a notification channel object with a unique string to identify it. Then, you can add the default settings for that channel and submit the channel. For example, to create a notification channel, you will face the following code:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

val name = getString(R.string.channel_name)

val descriptionText = getString(R.string.channel_description)

val importance = NotificationManager.IMPORTANCE_DEFAULT

val mChannel = NotificationChannel(CHANNEL_ID, name, importance)

mChannel.description = descriptionText



val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager

notificationManager.createNotificationChannel(mChannel)

}

As it was mentioned, if you are interested in organizing the appearance of your channels in the settings UI, you can build channel groups. This would be a reasonable idea while your app provides multiple user accounts. For instance, a social networking app might support for personal and work accounts. In this situation, each account might require multiple notification channels with identical functions and names. Each notification channel group needs an ID that must be unique within your package and a user-visible name. As a result, users can identify and control multiple notification channels, which have identical names simply.

In fact, submitting a channel is much like giving it as a gift to the user. Once you have submitted the channels, the user now owns them, and has full control over their notification settings. As an Android developer, you can no longer modify the settings of that channel. It means you can observe what settings the user has chosen, and you can make suggestions. Nevertheless, users have the ultimate control.

Notification Badges

In fact, badges or dots that appear on apps, which show the user that there are outstanding notifications. Notification badges appear on a launcher icon From 8.0 (API level 26) while the associated Android app has an active notification. Users can long-press on the app icon to open up the notifications.

A notification badges, the picture is provided by Google documents

Besides, there some cases in using a notification badges, which are provided by some solutions. First, you can have an opportunity to disable them on a per-channel basis by calling setShowBadge(false) on your NotificationChannel object. Second, each notification increments a number that are showed on the long- press menu, but you can be able to override this number in your application easily by calling call setNumber() on the notification. Eventually, you can modify a notification’s long-press menu icon by calling call Notification.Builder.setBadgeIconType() and pass in the BADGE_ICON_SMALL constant to display the small icon because the system shows the large icon by default.

Posting messaging notifications by MessagingStyle

First of all, you should use MessageStyle for sending messaging notifications. This also applies for building Android Auto or Android Wear. In the past, some developers switching between MessagingStyle and some other styles like BigPictureStyle in order to create that big image expansion presentation. However, with setData() method you do not require to accomplish that task. You can just use MessagingStyle, and this will create a consistent experience for the user. Furthermore, it is always a beneficial idea to add icon for people in notification. Google has highly recommended that you should use setIcon() to add avatar. Finally, if your app supports Smart Reply, you should add that into your notification because you can create a better experience for the user.

Feedback from your users

User can provide feedback to you that this is useful or not. And you should listen to that. So, from Android P, Google has added broadcasts for listening to block or change the state of your notification channels. Therefore, you should understand those, and you should react to them properly. In addition, you can query these APIs at runtime to find out how the user interacts with your channels.

In conclusion

A notification is a message that you can be able to show to the user outside of your application’s normal UI. Also, there are some important points for using notifications because it would be harmful experience for users in some inappropriate situations. This article considered some new features and best practices in Android notification.