My colleague Alistair introduced the concept of Notifications in Android and how to get them noticed by your users.
As Alistair says, notifications must be deployed with wisdom and cunning. Too much information may irritate the user resulting in the ultimate sanction - they block your notifications; at which point it’s game over!
For a developer, choosing the right volume of notifications is a tricky balance.
One person’s must-have information is another person’s noise and the user might have a different perspective from the developer about what is helpful.
Fortunately, Android O puts some extra tools into the hands of developers..
Android O introduces the concept of Notification Channels. These can be thought of as a wrapper or a grouping for certain types of notifications.
Notifications are assigned a channel when they are created and for all apps built for Android O, they must have at least one channel if they want to show any notifications.
The advantage of channels, from a user’s point of view, is that they can be customised.
The user has the power to downgrade (or upgrade!) the importance of a whole channel, to change the colours & sounds used by the channel or even to block a particular channel if you no longer want to receive that type of information.
This extra control will allow users to fine tune the way your app integrates into their smartphone ecosystem in a way that makes sense to them. Hopefully stopping them from getting annoyed & blocking your app altogether.
It’s easy to use Notification Channels but you will need to think about what is appropriate for the app you are developing - how many channels and what to post in them.
Android O also introduces the concept of Notification Badges, also known as Notification Dots.
Not too dissimilar to badges found in another well-known OS, in supported launchers they are displayed on top of the app icon and show there are notifications which haven’t been read or acted upon.
Users can turn badges on/off for particular notification channels or for the whole app.
1. Firstly a notification channel must be created in your app with a unique id (this can be done on application start-up as there is no harm trying to create a channel that already exists).
NotificationChannel channel = new NotificationChannel(“your_unique_channel_id”, “A user visible name for your channel”, NotificationManager.IMPORTANCE_DEFAULT); channel.setDescription( “A user visible description describing the purpose of your channel”); channel.setShowBadge(true); channel.enableLights(true); channel.setLightColor(Color.WHITE); channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE); getNotificationManager().createNotificationChannel(channel);
Nb. that once the channel is created, you can’t change its characteristics such as importance, sound etc. as the user might already have customised them - you’ll have to delete and recreate them.
2. When you create a notification, assign it the channel id
Notification.Builder builder = new Notification.Builder(getApplicationContext(), “your_unique_channel_id”) .setContentTitle(“A title for your notification”) .setContentText(“The contents of your notification”) .setSmallIcon(getSmallIcon()) .setAutoCancel(true); getNotificationManager().notify(aNotificationId, nb);
3. Job done
Alternatively, download the sample code and have a play github.com/googlesamples/android-NotificationChannels
Search over 200 blog posts from our team
Subscribe to our monthly digest of blogs to stay in the loop and come with us on our journey to make things better!