We at Plot always keep track of the latest developments for the platforms we are using. Here is a quick overview what will come to Android notifications when Android L is released and what features you can already use today to improve the look and feel of notifications on your watch!
You invest a lot of time in creating your app. Then spent a lot of time in getting people to install your app. It would be a waste if people would only install your app, use it once to never look at it again. Relevant notifications can keep your users engaged and therefore it’s important to get your notifications right. That’s why we are excited to see that notifications become even more powerful.
In Android notifications are supported from version one. since the beginning you had many possibilities to customize your notifications to match your app. During the course of time the number of ways to customize notifications has increased even more. Here is a short overview of the notification features introduced.
In Honeycomb the possibility was introduced to specify a remote view. Remote views allow you to place your own view elements on a notification. With this you can customize the layout completely and users can perform operations directly on the notifications without bringing the activities to the foreground.
In Jelly Bean notification styles and actions were introduced to make it easier to adjust the look and feel of a notification, and to let users directly perform operations on a notification. Common actions that can be done directly on a notification without opening the app are directly dismissing a message or planning a route to a location.
In the second milestone release of Jelly Bean notification listeners were introduced. These listeners allow other applications to access the notifications in the notification area and present them on another device or wearable. Before that, apps had to resort to using the accessibility service, which had limited functionality for dealing with notifications. It is probably the most likely reason that Android Wear requires at least Android 4.3.
Here is a larger overview of the history of what happened in Android related to notifications:
|Notification Listeners||18||4.3||Jelly Bean MR2|
Lock screen notifications
What’s new in L?
Android L is the next version of Android. There is no official release date, but a preview version is already available.
In Android L notifications will be presented at the lock screen, so users can first have a look at the notification before deciding whether it is worth to unlock your phone. There were already widgets by third parties that provided such functionality, but now it will be officially supported out of the box. The people behind Android acknowledge that notifications sometimes contain sensitive information, therefore the contents of the notifications won’t be shown by default. When the contents is hidden, you can only see what app sent the notification.
You control whether and how a notification is shown by setting the visibility property. There are three values:
VISIBILITY_PUBLIC: The notifications full content is shown on the lock screen. It won’t contain any special notification styles or actions.
VISIBILITY_PRIVATE: Shows basic information, such as the notification’s icon, but hides the notification’s full content. It possible to specify a public version by setting the publicVersion property of the notification which doesn’t contain any private information. The publicVersion will then be shown on the lock screen.
VISIBILITY_SECRET: The notification won’t be shown at all on the lock screen, not even the icon.
In Android L support for the RemoteControlClient will be removed. With the RemoteControlClient, introduced in Ice Cream Sandwich (4.0), it was possible to control your media playback directly from the lock screen. In Android L apps are expected to use notifications for that. For that the special MediaStyle is introduced.
There are also some improvements in the metadata of notifications. These changes affect the sorting and user experience.
It is already possible to set the priority of a notification to change the sort order since Jelly Bean (4.1), but now the HIGH and MAX priority cause a notification to be shown heads up.
You can specify about what person the notification is about. Android will then show notifications about the same person near each other.
Also notifications get a category. Depending on the message category, Android handles your notification differently when the device is in “Do not Disturb mode”. For example calls should be suppressed, but an alarm message should be allowed through.
Notifications on Wear
Android Wear is the operating system created by Google that runs on multiple smartwatches released recently. One of the reasons to get a watch with Android Wear is to get notifications directly on your watch. You don’t have to get your phone out of your pocket to see who sent you a message. If that isn’t enough, you can even read the message and reply to it directly from your watch.
When your app sends out notifications, then these notifications will also be shown on your wearable. You don’t have to modify your apps to let this happen. To make use of wearable specific features you do have to update your app.
Most of the functionality that is specifically for Android Wear is already available in the support-v4 library. When you are using gradle you can add the support library to your project with the following line:
One quick way to get good looking notifications on wearables is to make use of the notification styles. When you use the BigPicture style the picture is also shown on your watch.
The reference doesn’t specify a recommend size or aspect ratio for the image. This makes it hard to predict which part of the image will be visible and which part will be cropped. Also the image will likely be cropped and scaled different on your phone than on your wearable. So images with text probably won’t look good.
The first page will contain the notification card with the image as background. When you swipe to the left the notification card will go away so you have a full view on the notification. The last pages will contain the actions or the default action when no actions are specified.
If you want to show a lot of text, then this possible with the BigText style. Just as the name suggests, it shows the text. It truncates the text when it gets too long. This style is really useful if you want to prevent someone getting his phone out of his pocket.
For Android phones you are encouraged to limit the number of notifications for your app. When you have to share multiple events at the same time it is recommend to merge these together into a summary notification. However, on Android Wear these summary notifications don’t work that well. Users still have to get their phone out of their pocket to see what is really in these notifications.
But Android offers some ways to customize these kinds of notification, so it will work well on Android Wear. So read on.
When you want to share multiple events at the same time to the user you could create a notification for each of these and then group these notifications together. The stack of notifications appears as a single card on Android Wear, which you then can expand to view the details of each notification separately. Then you specify one summary notification for the group, which will be the only notification shown on a handheld device.
A small example in code:
final static String GROUP_KEY_EMAILS = "group_key_emails"; // Build the notification, setting the group appropriately Notification notification1 = new NotificationCompat.Builder(mContext) .setContentTitle("New mail from " + sender1) .setContentText(subject1) .setSmallIcon(R.drawable.new_mail); .setGroup(GROUP_KEY_EMAILS) .build(); // Issue the notification NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(notificationId1, notification1); Notification notification2 = new NotificationCompat.Builder(mContext) .setContentTitle("New mail from " + sender2) .setContentText(subject2) .setSmallIcon(R.drawable.new_mail); .setGroup(GROUP_KEY_EMAILS) .build(); notificationManager.notify(notificationId2, notification2); // Create an InboxStyle notification Notification summaryNotification = new NotificationCompat.Builder(mContext) .setContentTitle("2 new messages") .setSmallIcon(R.drawable.ic_small_icon) .setStyle(new NotificationCompat.InboxStyle() .addLine(subject1 + " " + sender1) .addLine(subject2 + " " + sender2) .setBigContentTitle("2 new messages")) .setGroup(GROUP_KEY_EMAILS) .setGroupSummary(true) .build(); notificationManager.notify(notificationId3, summaryNotification);
It is possible to adjust properties of the notification specifically for wearables. You can do this by specifying a WearableExtender.
You do this by creating the extender. You set the properties that are specific for the wearable and then extend the notification with the extender. Here is a small piece of sample code that shows how to hide the icon:
// Create a WearableExtender to add functionality for wearables NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender() .setHintHideIcon(true); // Create a NotificationCompat.Builder to build a standard notification // then extend it with the WearableExtender Notification notif = new NotificationCompat.Builder(mContext) .setContentTitle("New mail from " + sender) .setContentText(subject) .setSmallIcon(R.drawable.new_mail); .extend(wearableExtender) .build();
Some properties that are specific for wearables, such as the background image or the removal of the icon, can only be set from a WearableExtender. Other properties will overwrite the existing properties from the notification when shown on a wearable.
When you want to provide more information about a single event without having your users getting their phone out of their pocket, then multipage notifications are the type of notifications you are looking for.
Each page is defined as a notification, so you can design every page as you would with a normal notification. For example:
// Create second page notification Notification secondPageNotification = new NotificationCompat.Builder(this) .setStyle(bigTextStyle) .build(); // Add second page with wearable extender // and extend the main notification Notification twoPageNotification = new WearableExtender() .addPage(secondPageNotification) .extend(notificationBuilder) .build();
Actions and Voice Input
To completely remove the need to get your phone out of your pocket, you can perform actions directly from notifications. For example archiving an irrelevant email.
Sometimes an action requires more user input. For example the user wants to reply to a message. By specifying a RemoteInput for your action, the user can directly give input for the action. You can specify if the response is limited to a selection of available answers or that the user can give any form of answer.
A tip for testing, voice support can be tested in the emulator with the “Hardware keyboard”. RemoteInput functionality isn’t available in the compatibility library yet.
Lock screen notifications for Android L will make it easier for users to see which notifications they received and if they are worth unlocking their phone. By setting metadata on notifications Android will be able to better sort notifications, so notifications will become more relevant for the user. The features introduced in L aren’t in the support library yet, so making use of these features already isn’t easy. I would recommend waiting until these features are available in the support library.
Wearable notifications are already available today. All apps that send out notifications today on Android will show their notifications on wearables as well. However, to use these notifications optimally you should look into whether wearable specific features, such as stacking or paging notifications, are beneficial for your app. Most of the Wear specific features are already in the support library, so you can start using these features today without problem.