Search code examples
android-notificationsandroid-appcompatandroid-12

Android 12 In/out-call notification and prominent chip


According to Android 12 documentation there is special in/out-call notification that will show that called 'prominent chip'.

It's looking like that:
prominent chip

I tried to use the code from Android example:

// Create a new call with the user as caller.
Person incoming_caller = new Person.Builder()
    .setName("Jane Doe")
    .setImportant(true)
    .build();
    
Notification.Builder builder = Notification.Builder(context, CHANNEL_ID)
        .setContentIntent(contentIntent)
        .setSmallIcon(smallIcon)
        .setStyle(
            Notification.CallStyle.forIncomingCall(caller, declineIntent, answerIntent))
        .addPerson(incoming_caller);

In my application im using NotificationCompat and NotificationCompat.Builder but this line Notification.CallStyle.forIncomingCall is refer to non Compat versions so I can't use the logic of forIncomingCall to my existing notification.


Solution

  • Edit: The 1.10.0 release of androidx:core finally adds CallStyle support for NotificationCompat!

    https://developer.android.com/jetpack/androidx/releases/core#1.10.0


    The NotificationCompat class from AndroidX hasn't been updated to include this new style yet - you can search NotificationCompat on https://cs.android.com to check the latest version of the file, and then you'll have to wait for a new release of the androidx.core:core library.

    In the meantime, you'll have to use the platform Notification type if you want to use the new call style:

    if (Build.VERSION.SDK_INT >= 31) {
      // Use Notification with Notification.CallStyle
    } else {
      // use NotificationCompat
    }