Developer Guide to Implement Bubble API in Android Application

Developer Guide to Implement Bubble API in Android Application

Introduction

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

Guidelines

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).

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.

4. Create MetaData

  • We need to create metadata and a person objects to pass in the notification.
  • 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.

6. Create Shortcut

8. Create Notification

  • Finally, create the notification and set the metadata using the method setBubbleMetadata.
  • 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.

Conclusion

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
Darshak Jungi completed his education in Master of Computer. And working as a software developer in Dev it. With three years of experience. He has expertise in android java and kotlin. He spends his extra time doing multiple sports activities.

Latest posts by Darshak Jungi (see all)

Leave a Reply

Your email address will not be published.