Read More
Redeem Now
Read now

Bubble in Android

Bubbles

 

In Android Q to improve the OS that needed there were some feature needs to be updated, one of them is notifications. Notification is an important part of Android, and in Android Q, Google has introduced a new feature that keeps important messaging or chats notifications on the front as Facebook Messenger chat head.

The feature is being called Bubbles. When you get a notification of a text message or anything else like a Facebook messenger message, you can now turn that regular notification into a chat bubble that floats on the top of your screen. No matter what you’re doing on your phone, chat bubbles ensure you always have easy access to that conversation. Bubbles make it easy for users to see and participate in conversations. 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.

 

Let’s understand how to implement the code:

 

Bubbles are created via the Notification API, so you send your notification as normal. If you want your notification to display as a bubble, you need to attach some extra data to it.

The expanded view of a bubble is created from an activity that you choose. The Activity needs to be configured to display properly as a bubble. The activity must be resizeable and embedded. If it lacks either of these requirements it displays as a notification instead.

 

1: AndroidManifest.xml:

If your app shows multiple bubbles of the same type, like multiple chat conversations with different contacts, the activity must be able to launch multiple instances. When devices running Android 10, notifications are not shown as bubbles unless you set it to documentLaunchMode as “always”. Beginning with Android 11, you do not require to set this value explicitly, as the system automatically sets all conversations’ documentLaunchMode as “always”.

2: activity_main.xml:

 

3: MainActivity.kt:

Use this function if the action if you want as a bubble, like clicking on a button to start a chat as Facebook chat head. In this case, it also makes sense to suppress the initial notification sent when a bubble is created.

4: In activity_bubble.xml:

 

5: BubbleActivity.kt:

6: strings.xml:

 

On Android API level 29(version 10), the chat head will not work normally you have to enable the bubble feature from the developer option.

 

Final results:

 

. . . . . . . . . .

That’s it from my side for today, thanks for reading it until now.

. . .

Comment

Add Your Comment

Be the first to comment.

css.php
Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again
Close