public class

NotificationCompat.CallStyle

extends NotificationCompat.Style

 java.lang.Object

androidx.core.app.NotificationCompat.Style

↳androidx.core.app.NotificationCompat.CallStyle

Overview

Helper class for generating large-format notifications that include a caller and required actions, and indicate an incoming call.
If the platform does not provide large-format notifications, this method has no effect. The user will always see the normal notification view.
This class is a "rebuilder": It attaches to a Builder object and modifies its behavior, like so:

 Notification notification = new NotificationCompat.Builder(mContext)
     .setSmallIcon(R.drawable.new_post)
     .setStyle(
             new Notification.CallStyle.forIncomingCall(caller, declineIntent, answerIntent))
     .build();
 

Note that for CallStyle Notifications on API versions before 31 to be ranked as they are in API versions 31+, they must be associated with a foreground service. Additionally, CallStyle Notifications on API versions before 31 can achieve the similar ranking by marking the Notification as colorized, using NotificationCompat.Builder.setColorized(boolean).

Summary

Fields
public static final intCALL_TYPE_INCOMING

Call type for incoming calls.

public static final intCALL_TYPE_ONGOING

Call type for ongoing calls.

public static final intCALL_TYPE_SCREENING

Call type for calls that are being screened.

public static final intCALL_TYPE_UNKNOWN

Unknown call type.

from NotificationCompat.StylemBuilder
Constructors
publicCallStyle()

publicCallStyle(NotificationCompat.Builder builder)

Creates a CallStyle linked to a notification builder.

Methods
public voidaddCompatExtras(Bundle extras)

This is called with the extras of the framework Notification during the NotificationCompat.Builder.build() process, after apply() has been called.

public voidapply(NotificationBuilderWithBuilderAccessor builder)

Applies the compat style data to the framework Notification in a backwards compatible way.

public booleandisplayCustomViewInline()

public static NotificationCompat.CallStyleforIncomingCall(Person person, PendingIntent declineIntent, PendingIntent answerIntent)

Creates a CallStyle for an incoming call.

public static NotificationCompat.CallStyleforOngoingCall(Person person, PendingIntent hangUpIntent)

Creates a CallStyle for an ongoing call.

public static NotificationCompat.CallStyleforScreeningCall(Person person, PendingIntent hangUpIntent, PendingIntent answerIntent)

Creates a CallStyle for a call that is being screened.

public java.util.ArrayList<NotificationCompat.Action>getActionsListWithSystemActions()

Gets the actions list for the call with the answer/decline/hangUp actions inserted in the correct place.

protected java.lang.StringgetClassName()

protected voidrestoreFromCompatExtras(Bundle extras)

public NotificationCompat.CallStylesetAnswerButtonColorHint(int color)

Sets an optional color to be used as a hint for the Answer action button's color.

public NotificationCompat.CallStylesetDeclineButtonColorHint(int color)

Sets an optional color to be used as a hint for the Decline or Hang Up action button's color.

public NotificationCompat.CallStylesetIsVideo(boolean isVideo)

Sets whether the call is a video call, which may affect the icons or text used on the required action buttons.

public NotificationCompat.CallStylesetVerificationIcon(Bitmap verificationIcon)

Sets an optional icon to be displayed with text as a verification status of the caller.

public NotificationCompat.CallStylesetVerificationIcon(Icon verificationIcon)

Sets an optional icon to be displayed with text as a verification status of the caller.

public NotificationCompat.CallStylesetVerificationText(java.lang.CharSequence verificationText)

Sets optional text to be displayed with an icon as a verification status of the caller.

from NotificationCompat.StyleapplyStandardTemplate, build, buildIntoRemoteViews, clearCompatExtraKeys, createColoredBitmap, extractStyleFromNotification, makeBigContentView, makeContentView, makeHeadsUpContentView, setBuilder
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Fields

public static final int CALL_TYPE_UNKNOWN

Unknown call type. See NotificationCompat.EXTRA_CALL_TYPE.

public static final int CALL_TYPE_INCOMING

Call type for incoming calls. See NotificationCompat.EXTRA_CALL_TYPE.

public static final int CALL_TYPE_ONGOING

Call type for ongoing calls. See NotificationCompat.EXTRA_CALL_TYPE.

public static final int CALL_TYPE_SCREENING

Call type for calls that are being screened. See NotificationCompat.EXTRA_CALL_TYPE.

Constructors

public CallStyle()

public CallStyle(NotificationCompat.Builder builder)

Creates a CallStyle linked to a notification builder.

Parameters:

builder: the notification builder to link

Methods

public static NotificationCompat.CallStyle forIncomingCall(Person person, PendingIntent declineIntent, PendingIntent answerIntent)

Creates a CallStyle for an incoming call. This notification will have a decline and an answer action, will allow a single custom action, and will have a default content text for an incoming call.

Parameters:

person: the person displayed as the caller the person also needs to have a non-empty name associated with it
declineIntent: the intent to be sent when the user taps the decline action
answerIntent: the intent to be sent when the user taps the answer action

public static NotificationCompat.CallStyle forOngoingCall(Person person, PendingIntent hangUpIntent)

Creates a CallStyle for an ongoing call. This notification will have a hang up action, will allow up to two custom actions, and will have a default content text for an ongoing call.

Parameters:

person: the person displayed as being on the other end of the call the person also needs to have a non-empty name associated with it
hangUpIntent: the intent to be sent when the user taps the hang up action

public static NotificationCompat.CallStyle forScreeningCall(Person person, PendingIntent hangUpIntent, PendingIntent answerIntent)

Creates a CallStyle for a call that is being screened. This notification will have a hang up and an answer action, will allow a single custom action, and will have a default content text for a call that is being screened.

Parameters:

person: the person displayed as the caller the person also needs to have a non-empty name associated with it
hangUpIntent: the intent to be sent when the user taps the hang up action
answerIntent: the intent to be sent when the user taps the answer action

public NotificationCompat.CallStyle setIsVideo(boolean isVideo)

Sets whether the call is a video call, which may affect the icons or text used on the required action buttons.

public NotificationCompat.CallStyle setVerificationIcon(Icon verificationIcon)

Sets an optional icon to be displayed with text as a verification status of the caller.

public NotificationCompat.CallStyle setVerificationIcon(Bitmap verificationIcon)

Sets an optional icon to be displayed with text as a verification status of the caller.

public NotificationCompat.CallStyle setVerificationText(java.lang.CharSequence verificationText)

Sets optional text to be displayed with an icon as a verification status of the caller.

public NotificationCompat.CallStyle setAnswerButtonColorHint(int color)

Sets an optional color to be used as a hint for the Answer action button's color. The system may change this color to ensure sufficient contrast with the background. The system may choose to disregard this hint if the notification is not colorized.

public NotificationCompat.CallStyle setDeclineButtonColorHint(int color)

Sets an optional color to be used as a hint for the Decline or Hang Up action button's color. The system may change this color to ensure sufficient contrast with the background. The system may choose to disregard this hint if the notification is not colorized.

public boolean displayCustomViewInline()

Returns:

Whether custom content views are displayed inline in the style

protected void restoreFromCompatExtras(Bundle extras)

public void addCompatExtras(Bundle extras)

This is called with the extras of the framework Notification during the NotificationCompat.Builder.build() process, after apply() has been called. This means that you only need to add data which won't be populated by the framework Notification which was built so far. Moreover, recovering builders and styles is only supported at API 19 and above, no implementation is required for current BigTextStyle, BigPictureStyle, or InboxStyle.

protected java.lang.String getClassName()

public void apply(NotificationBuilderWithBuilderAccessor builder)

Applies the compat style data to the framework Notification in a backwards compatible way. All other data should be stored within the Notification's extras.

public java.util.ArrayList<NotificationCompat.Action> getActionsListWithSystemActions()

Gets the actions list for the call with the answer/decline/hangUp actions inserted in the correct place. This returns the correct result even if the system actions have already been added, and even if more actions were added since then.