androidnotificationswhatsappvoipandroid-statusbar

How to show ongoing call timer in android status bar like whats app


I am developing VOIP calling application and I want to show timer on "status bar" for active ongoing call like whats app (highlighted in pink circle attached screenshot)

enter image description here

Does anyone know how to do that? I am using foreground service with notification for indicating ongoing active call.


Solution

  • We can do this using 'Notification.CallStyle.forOnGoingCall' (Android 12)

    Android 12 adds the new notification style Notification.CallStyle for phone calls. Using this template lets your app indicate the importance of active calls by displaying a prominent chip that shows the time of the call in the status bar; the user can tap this chip to return to their call.

    More info : New phone call notifications allowing for ranking importance of incoming calls

    // Create a call style notification for an ongoing call.
    Notification.Builder builder = Notification.Builder(context, CHANNEL_ID)
    .setContentIntent(contentIntent)
    .setSmallIcon(smallIcon)
    .setStyle(
        Notification.CallStyle.forOnGoingCall(caller, hangupIntent))
    .addPerson(second_caller);