构建安卓对话气泡

We recently rolled out support for Conversation Bubbles for DMs and Group DMs on Android 11.

我们最近在安卓11上推出了对DMs和群组DMs对话气泡的支持。

In case you’re not familiar with Conversation Bubbles, take a look at the video below. Basically, they are a way to pop out a conversation from a notification into a Bubble that will draw over other apps, making multitasking while chatting easy and comfortable.

如果你对对话泡泡不熟悉,可以看看下面的视频。基本上,它们是一种将对话从通知中跳出,变成一个气泡的方式,它将在其他应用程序上绘制,使聊天时的多任务操作变得简单和舒适。

This post will describe how we built support for these bubbles, the challenges we faced along the way, and how we overcame them. Some details were simplified where it made sense to, but stayed relatively close to our actual implementation overall.

这篇文章将描述我们如何建立对这些泡沫的支持,我们一路走来面临的挑战,以及我们如何克服它们。在有意义的地方,一些细节被简化了,但总体上与我们的实际实施保持相对接近。

Prerequisites

先决条件

According to the official Android documentation, there are three basic requirements for supporting Bubbles from a notification:

根据安卓官方文档,从通知中支持气泡有三个基本要求。

  1. The notification needs to be built using MessagingStyle, the native Android API for messaging notifications.
  2. 该通知需要使用MessagingStyle ,即用于消息通知的本地Android API来构建。
  3. The notification needs to have an associated Sharing Shortcut.
  4. 该通知需要有一个相关的共享快捷方式
  5. There needs to be a [BubbleMetadata](https://developer.android.com/reference/android/app/Notification.BubbleMetadata) object set on the notification, pointing to a resizable, embedded Activity.
  6. 在通知上需要设置一个[BubbleMetadata](https://developer.android.com/reference/android/app/Notification.BubbleMetadata) 对象,指向一个可调整大小的嵌入式活动。

MessagingStyle

信息传递方式

MessagingStyle was introduced in Android 7 and gives developers a way of building notifications for messaging apps using structured data. This was a huge step forward from the previous approach where developers had to style their own messaging notifications using spans and string concatenation. Luckily, we had recently rewritten our notification code and migrated it to MessagingStyle.

MessagingStyle 是在安卓7中引入的,为开发者提供了一种使用结构化数据为消息应用程序构建通知的方法。这是一个巨大的进步,因为在以前的方法中,开发者必须使用跨度和字符串连接来设计自己的消息通知。幸运的是,我...

开通本站会员,查看完整译文。

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.1. UTC+08:00, 2026-04-25 18:03
浙ICP备14020137号-1 $访客地图$