Group Messaging in Android Auto

Posted by David Nelloms, Software Engineer



Communicating with a group of people is a common use case for many messaging
apps. However, it may be difficult to know how the href="https://developer.android.com/training/auto/messaging/index.html">Android
Auto messaging API applies to group conversations. Here are some tips for
getting started with group messaging in Android Auto:


Conversation Name



When constructing the UnreadConversation builder, you are required to pass in a
name. This is the name of the conversation that is displayed to the user when
messages arrive.



UnreadConversation.Builder unreadConvBuilder =
new UnreadConversation.Builder(conversationName)
.setReadPendingIntent(msgHeardPendingIntent)
.setReplyAction(msgReplyPendingIntent, remoteInput);


For one-on-one conversations, this is simply the name of the other participant.
For group conversations, it is best to choose one of two options for the name:



  1. Conversation title: If your app supports adding a title to group
    conversations, use the title for the name parameter to be consistent with your
    in-app experience. This field is similar to href="https://developer.android.com/reference/android/support/v4/app/NotificationCompat.MessagingStyle.html#setConversationTitle(java.lang.CharSequence)">NotificationCompat.MessagingStyle#setConversationTitle.
  2. A list of participants: Build a comma-separated list of participants for the
    name parameter to identify the group. Note that this is read aloud by the
    text-to-speech system, so you may need to abbreviate the list for large groups.
    You should balance allowing users to uniquely identify the group with the time
    taken to listen to messages.

Text to Speech Formatting



Getting text to sound natural using a TTS system is a challenging problem.
There are teams working hard to improve this, but there are steps you can take
to create a better user experience with the current capabilities. The Android
Auto messaging API does not yet have an option for pairing participants with
individual messages in a group conversation. This is problematic for drivers
when there are multiple unread messages from multiple participants in a group
conversation, as the drivers cannot see which group member sent which message.
One solution is to prepend the sender's name to the message whenever the sender
changes so that the names are read aloud to the driver.



CharSequence currentSender = null;
for (Message message : myMessages) {
StringBuilder messageText = new StringBuilder();
CharSequence sender = message.getSender();
// Maybe append sender to indicate who is speaking.
if (!TextUtils.isEmpty(sender) && !sender.equals(currentSender)) {
if (currentSender != null) {
// Punctuation will briefly pause TTS readout between senders.
messageText.append(". ");
}
currentSender = sender;
messageText.append(sender.toString().toLowerCase(Locale.getDefault()));
// Punctuation will separate sender from message in TTS readout.
messageText.append(": ");
}
messageText.append(message.getText());
unreadConvBuilder.addMessage(messageText.toString());
}


Some things to note about the above sample code:


  • Adding punctuation is not strictly necessary, but it can produce a more
    natural sounding result.
  • The sender names are converted to lowercase. This is workaround for a quirk
    where the TTS implementation vocalizes ". " as "dot" when preceding a capital
    letter on some devices.

Get participants



In searching for how to handle group messaging, you may have noticed href="https://developer.android.com/reference/android/support/v4/app/NotificationCompat.CarExtender.UnreadConversation.html#getParticipants()">UnreadConversation#getParticipants.
This can be confusing as there is no mechanism to add multiple participants in
the builder. The builder implementation populates the array with the
conversation name passed to its constructor. Internally, Android Auto uses the
singular href="https://developer.android.com/reference/android/support/v4/app/NotificationCompat.CarExtender.UnreadConversation.html#getParticipant()">UnreadConversation#getParticipant,
which returns the first element of the participants array, to populate the title
in the notification view.


Stay tuned



The Android Auto team is working on ways to make messaging with drivers simpler
and more intuitive for app developers. Stay tuned for future updates so that
you can continue to deliver a great user experience!




Komentar

Postingan populer dari blog ini

Google Play Referrer API: Track and measure your app installs easily and securely

Boosting developer success on Google Play

And the 2019 Google Play Award nominees are...