
Android Q- Implementing Bubbles
It’s been a while nice Android Q Beta preview was released. With it came an exciting new feature of Bubbles– a new way for users to multitask and interact with your app for performing important tasks like marking/unmarking items on a todo list, replying to a chat message, or performing a task within your app without having to leave current app.
Bubbles are built into the Notification system. They float on top of other app content and follow the user wherever they go. Bubbles can be expanded to reveal app functionality and information, and can be collapsed when not being used.
In this article, I am going to demonstrate a sample for implementing Bubbles for a simple reminder app where a bubble pops up at a user-specified time to remind and enable the user to make a call or send an email.
Before I begin, Joe Birch has written an excellent piece exploring the Bubbles API and various methods related to it. I suggest you check it here before reading further.
Prerequisites
First things first- Prerequisites for implementing bubbles are:
- The latest preview version of Android Studio 3.5 Preview
- Android Q Preview SDK
- Get Android Q Beta for Android emulator or your pixel device
- Update build configuration in your app’s build.gradle to target android-Q
1android {
2 compileSdkVersion 'android-Q'
3 defaultConfig {
4 ...
5 minSdkVersion 'Q'
6 targetSdkVersion 'Q'
7 ...
8 }
9 ...
10}
That’s it! You are now ready to implement Bubbles for your app!
Building Bubbles
The Bubble view is nothing but an activity that is specifically configured to be resizeable, embedded, and always launched in document UI mode.
1<activity
2 android:name=".BubbleActivity"
3 android:theme="@style/AppTheme.NoActionBar"
4 android:label="Reminder"
5 android:allowEmbedded="true"
6 android:documentLaunchMode="always"
7 android:resizeableActivity="true" />
- allowEmbedded=”true”- Indicates that the activity can be launched as the embedded child of another activity.
- resizeableActivity=”true”- Specifies whether the app supports multi-window display.
- documentLaunchMode=”always”- If your app shows multiple bubbles of the same type, the activity is launched in multiple instances.

Bubbles are created via the Notification API. Therefore, to send bubbles we need to follow these steps:
1. Create a PendingIntent to specify the bubble activity (activity shown inside the bubble)
1// Create bubble intent
2val target = Intent(context, BubbleActivity::class.java)
3val bubbleIntent = PendingIntent.getActivity(context, 0, target, 0)
2. Create BubbleMetadata object via Notification.BubbleMetadata.Builder and specify the target bubble intent (to be opened when the user clicks on the bubble) with .setIntent().
1// Create bubble metadata
2val bubbleMetadata = Notification.BubbleMetadata.Builder()
3 .setDesiredHeight(200)
4 .setIcon(Icon.createWithResource(context, R.mipmap.ic_launcher_round))
5 .setIntent(bubbleIntent)
6 .build()
3. Add this BubbleMetadata object to a notification via setBubbleMetadata()
1// Create notification
2val notificationBuilder = Notification.Builder(context, NOTIFICATION_CHANNEL_ID)
3 .setContentIntent(pendingIntent)
4 .setContentTitle(notificationTitle)
5 .setSmallIcon(R.mipmap.ic_launcher_round)
6 .setBubbleMetadata(bubbleMetadata)
Note: Although we can set the icon via setSmallIcon(), the icon is not displayed in Q Beta 2.
4. Set up notification channels for ≥ Oreo as usual and display the notification.
1val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
2
3if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
4 val importance = NotificationManager.IMPORTANCE_HIGH
5 val notificationChannel = NotificationChannel(NOTIFICATION_CHANNEL_ID, "Reminder Alarms", importance)
6 notificationManager.createNotificationChannel(notificationChannel)
7}
8val random = Random()
9val id = random.nextInt(9999 - 1000) + 1000
10notificationManager.notify(id, notificationBuilder.build())
Final Output


Note: This is from the Android Q Beta 2 release and there are a lot more releases planned for Android Q and they are just getting started with bubbles so there might be some changes and many additions to this initial preview.
Check out the full source code for my sample here.
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Block quote
Ordered list
- Item 1
- Item 2
- Item 3
Unordered list
- Item A
- Item B
- Item C
Bold text
Emphasis
Superscript
Subscript