Developer Guide to Implement Bubble API in Android Application

Developer Guide to Implement Bubble API in Android Application


Google recently introduced bubbles API in 2019 for display notification. In Android Q, this has made chat head notifications part of the Android platform as bubble API. This bubble notification feature was introduced first for Pixel devices only and worked similar to the Facebook messenger chat bubble. In Android 10, this wasn’t a stable release, and users had to enable it from developer options in their settings.

Bubble API’s final version came with Android 11. Bubbles are a preview feature in Android 11 that helps you perform more than one task or use more than one application at a time. Android has a native implementation to make conversations easier and more accessible to the user. They are built into the notification system and float on top of other apps.

In this blog, we will learn how to use bubble notifications in our application. So, get started.

Bubble notifications only appear when it meets the conversation requirement. So here are a few limitations for when notifications can be shown as bubbles.

Limitations in Android 10

⦁ For Notifications, we use Messingingstyle, and a Person added

⦁ When notifications are sent, the app must be in the foreground

Limitations on Android 11

⦁ Notifications use MessagingStyle


Conversation Requirements

⦁ First, to fulfil the notification conversation requirements – we need to implement long-lived dynamic or sharing shortcuts and attach the shortcut id to your messaging style notification.

How are Bubbles implemented?

1. Check SDK version

  •  The first step is to ensure that our application targets Android 11 (API Level 30).
       Android {
	    compileSdkVersion 30
	    buildToolsVersion "30.0.2"

	    defaultConfig {
	        targetSdkVersion 30

2. Configure Activity

  • This activity is displayed as a bubble, and it must be resizable and embedded.
  • So, in Android 10, notifications are not displayed as bubbles unless you set documentLaunchMode = “always” in the manifest file. However, in Android 11, there is no need to set this value because the system automatically sets all conversations’ documentLaunchMode to “always.”

3. Create Intent

  • We must create a PendingIntent that navigates to bubble activity.
val screen = Intent(context,
val bubbleInt = PendingIntent.getActivity(context, 0, screen, 0 )

4. Create MetaData

  • We need to create metadata and a person objects to pass in the notification.
 Val bubbleData=Notification.BubbleMetadata.Builder(bubbleInt ,
 Icon.createWithResource(context, R.drawable.icon))
  • When you click on a bubble, it shows the content, but you can always auto-expand the bubble using this method setAutoExpand(true).

5. Create Person

  • We have to create person object with the information about a chat partner.
	 val chatPartner = Person.Builder()
    	.setName("Chat partner")

6. Create Shortcut

      	 val shortcut =ShortcutInfo.Builder(mContext, shortcutId)

8. Create Notification

  • Finally, create the notification and set the metadata using the method setBubbleMetadata.
	  val builder = Notification.Builder(context, CHANNEL_ID)
  • When setting normal values in the notification builder the user can turn off bubbles from the system setting, and then the normal notification will be shown instead of bubbles.
	with(builder) {
   		   setContentTitle("New message")
      		  PendingIntent.getActivity(   context,    0,
//then call the notification manager to send it


By following the above steps, you would have learned to properly implement bubble-style notifications in your application. The blog also stated the important points that should be kept in mind while implementing bubble notifications. If you have any doubts about this topic, please feel free to drop a comment, and our DEV IT engineers will get back to you.

The following two tabs change content below.

Darshak Jungi

Software Developer (Android) at DEV Information Technology Ltd
Divyanshu is a software developer at DEV IT and has 3 Years of experience in IT industry. He has expertise in android java and kotlin. He spends his extra time doing multiple sports activities.

Leave a Reply

Your email address will not be published. Required fields are marked *