Dedicated Server

Android Q Bubbles in Action

Android Q bubble

Hi guys, in this tutorial we will be discussing about the new bubbles feature introduced in Android Q. You might have already come across facebook chat heads, well the new bubble feature in android Q is a similar feature. But for android Q Bubbles, it is supported by the android OS itself. From now on, we just have to use the bubbles feature to build such widgets.

You may check here >> to see an intro about android Q bubbles mentioned in the google i/o 2019

As mentioned in,

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.
 Features and Characteristics :

  • The bubbles float on top of other apps and hence allows seamless multitasking.
  • Since the bubbles are built into the notification system, it appears as a normal notification in case the device is locked or if the always-on-display is active
  • Bubbles are basically an opt out feature - i.e, the user can choose whether to have the bubbles enabled for an app or not.

Now we will see how to implement this in code :

First of all update your app level build.gradle like shown below

The activity which opens up when a bubble is clicked needs to follow certain guidelines to function properly with bubbles.So inside your AndroidManifest.xml, an activity should be declared as resizeable, embedded, and always launch in document UI mode like shown below

Now in order to create a bubble notification, you will need to :

  • Create a notification like you normally do
  • Create a bubble metadata object by calling Notification.BubbleMetadata.Builder
  • Then by using setBubbleMetadata  add the bubble metadata into the notification

So update your file like show below :

You may also create a bubble which is expanded automatically by specifying setAutoExpandBubble() and setSuppressInitialNotification() as true. Skip this step if you don't want the bubble to upen automatically
Now your activity_main.xml should be updated like this :

No comments:

Post a Comment