A few weeks back we saw the announcement of the Android Q beta release 🎉 With this version of Android comes a collection of exciting changes which we need to get our apps ready for. In this set of articles I’m going to be diving into each one of these so that we are fully prepared for getting our apps ready!
As outlined in the beta (version 2) release notes for Android Q, we are seeing the introduction of what are known as bubbles. These bubbles aim to improve multitasking as well as provide a unified way for apps to provide such a feature – whilst some applications already have this functionality available (such as facebook messenger), this system level feature will create a more consistent experience for users and make it simpler for developers to implement such a thing.
In the sample app provided by Google, you can see a simple messaging app that has implemented this feature. Whilst this and the screenshot above display messaging style interactions, bubbles can be used to provide access to various content types that allow you to improve the multitasking experience for your users. For example, may you pop-up a todo list which the user can quickly resume to mark something off, or even
The Bubble functionality is made up of a few changes throughout Notification related classes. Two core changes are to the Notification API and first of all, the notification builder class has a new method called setBubbleMetaData(). This takes an instance of the new BubbleMetadata class which will be used to display the desired app content in a floating window from the selected Bubble.
Notification.Builder(context, YOUR_NOTIFICATION_CHANNEL) .setBubbleMetadata(someBubbleMetaData)
You’ll notice there that we pass in a notification channel reference when building our notification. One important thing to note here is that the NotificationChannel class now has a canBubble() method – this allows us to check whether or not our application is able to make use of notification bubbles. The reason this exists is because users are able to disable notification bubbles from within the system settings section of your app. The NotificationChannel also has a setAllowBubbles() method that we can use to set whether or not a channel support bubbles, before the channel is submitted to the notification manager.
Note: There is also a areBubblesAllowed() method that has been added to the NotificationManager class. Both this and then canBubble() method from the NotificationChannel class should be checked before showing a Bubble.
Now that we’ve got our notification builder and have checked that we can actually show bubbles for our application, it’s time to crate our Bubble Metadata. We start off by making use of the Builder to build our BubbleMetaData.
We can then use setAutoExpandBubble() to declare whether or not the bubble contents will be automatically expanded on creation, provided that the given application is currently in the foreground. The guidelines state that this should only be assigned to true if the user has requested for the bubble to be shown – which makes sense as this could be an unexpected behaviour for the user for a bubble to suddenly pop open out of nowhere.
Next, we can us setDeleteIntent() to assign an intent which should be used when the user removes the bubble. On the other hand, setIntent() can be used to assign an intent to be used when the bubble is opened. When this is done, the content of the intent will be displayed within a floating window from the bubble. When this bubble is displayed the corresponding notification will remain within the system bar. However, we can make use of the setSuppressInitialNotification() method of the builder to declare that the notification should not be shown within the system bar. This method would make sense to be used when setAutoExpandBubble() is used – as in this case, it will have been the user triggering the launch of the bubble so the notification would not serve any purpose.
There are also some display related values we can set for the BubbleMetadata. First of all we can use setDesiredHeight() to assign a height to be used for the content displayed via the setIntent() property. We can also use setIcon() and setTitle() to customiser the look and feel of the displayed bubble.
In this post we’ve taken a quick look at the new Bubble feature coming in Android Q, along with how we can implement it within our own applications. I’m quite looking forward to applications making use of this and the consistent experience that it will bring to the platform. Will you be making use of Bubbles or do you have any questions about them? Feel free to reach out if so!
Whilst you’re here, a side-project that I’ve been working on has been nominated for a Webby Award. I would greatly appreciate your vote here!