0

So I have application that as side action, sends out notification towards Android Auto (not just towards AA, but also other notifications).

Till now we just added UnreadConversation into NotificationCompat.Builder

    val builder = NotificationCompat.Builder(context, notificationHolder.channelID)
    ... 
    if (unreadConversationForAndroidAuto != null) {
        builder.extend(NotificationCompat.CarExtender()
            .setUnreadConversation(unreadConversationForAndroidAuto))
    }

NotificationCompat.CarExtender().setUnreadConversation() is now deprecated and I can't find any documentation on how to add MessagingStyle (this is what replaced UnreadConversation) as additional message to Notification.

I don't want to send 2 different messages, where we previosuly sent just one. How can I easiest refactor this to go new way.

1 Answers1

1

Before, you would have

builder.setContentTitle(notificationDetails)
        .setSmallIcon(R.drawable.smarter_garage_icon)
        .setContentText("Click notification to return to app")
        .setContentIntent(notificationPendingIntent)
        .setContentTitle( "content title" )
        .setWhen( Calendar.getInstance().get( Calendar.SECOND ) )
        .extend(new NotificationCompat.CarExtender()
                .setUnreadConversation(getUnreadConversation(context) ) );

and now you need the new methods, you can try like below:

import androidx.core.app.NotificationCompat.MessagingStyle.Message;

        // Define the notification settings.
        builder.setContentTitle(notificationDetails)
                .setSmallIcon(R.drawable.smarter_garage_icon)
                .setContentText("Click notification to return to app")
                .setContentIntent(notificationPendingIntent)
                .setContentTitle( "content title" )
                .setWhen( Calendar.getInstance().get( Calendar.SECOND ) )
                .setStyle(new NotificationCompat.InboxStyle()).setTimeoutAfter(10000).setContentText("Hello").addPerson(new Person.Builder().build()).build();
80sTron
  • 59
  • 1
  • 5