23 Mayıs 2017
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:
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:
In searching for how to handle group messaging, you may have noticed 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 UnreadConversation#getParticipant, which returns the first element of the participants array, to populate the title in the notification view.
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!