// Create a new call, setting the user as the caller.valincomingCaller=Person.Builder().setName("Jane Doe").setImportant(true).build()
Java
// Create a new call with the user as the caller.PersonincomingCaller=newPerson.Builder().setName("Jane Doe").setImportant(true).build();
来电
使用 forIncomingCall() 方法为
来电。
Kotlin
// Create a call style notification for an incoming call.valbuilder=Notification.Builder(context,CHANNEL_ID).setContentIntent(contentIntent).setSmallIcon(smallIcon).setStyle(Notification.CallStyle.forIncomingCall(caller,declineIntent,answerIntent)).addPerson(incomingCaller)
Java
// Create a call style notification for an incoming call.Notification.Builderbuilder=Notification.Builder(context,CHANNEL_ID).setContentIntent(contentIntent).setSmallIcon(smallIcon).setStyle(Notification.CallStyle.forIncomingCall(caller,declineIntent,answerIntent)).addPerson(incomingCaller);
当前通话
使用 forOngoingCall() 方法为
通话中。
Kotlin
// Create a call style notification for an ongoing call.valbuilder=Notification.Builder(context,CHANNEL_ID).setContentIntent(contentIntent).setSmallIcon(smallIcon).setStyle(Notification.CallStyle.forOngoingCall(caller,hangupIntent)).addPerson(second_caller)
Java
// Create a call style notification for an ongoing call.Notification.Builderbuilder=newNotification.Builder(context,CHANNEL_ID).setContentIntent(contentIntent).setSmallIcon(smallIcon).setStyle(Notification.CallStyle.forOngoingCall(caller,hangupIntent)).addPerson(second_caller);
过滤来电
使用 forScreeningCall() 方法为以下事件创建通话样式通知:
来电过滤
Kotlin
// Create a call style notification for screening a call.valbuilder=Notification.Builder(context,CHANNEL_ID).setContentIntent(contentIntent).setSmallIcon(smallIcon).setStyle(Notification.CallStyle.forScreeningCall(caller,hangupIntent,answerIntent)).addPerson(second_caller)
Java
// Create a call style notification for screening a call.Notification.Builderbuilder=newNotification.Builder(context,CHANNEL_ID).setContentIntent(contentIntent).setSmallIcon(smallIcon).setStyle(Notification.CallStyle.forScreeningCall(caller,hangupIntent,answerIntent)).addPerson(second_caller);
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Create a call style notification for call apps\n\nOn Android 12.0 (API level 31) and later, the system provides the\n[`CallStyle`](/reference/android/app/Notification.CallStyle) notification template to distinguish call notifications from\nother types of notifications. Use this template to create incoming or\nongoing call notifications. The template supports large-format notifications\nthat include caller information and required actions such as answering or\ndeclining calls.\n\nBecause incoming and ongoing calls are high priority events, these notifications\nreceive top priority in the notification shade. This ranking also enables the\nsystem to forward these prioritized calls to other devices.\n\nThe `CallStyle` notification template includes the following required actions:\n\n- **Answer** or **Decline** for incoming calls.\n- **Hang up** for ongoing calls.\n- **Answer** or **Hang up** for call screening.\n\nActions in this style appear as buttons, with the system automatically adding\nappropriate icons and text. Manual labeling of the buttons is not supported.\nFor more information about notification design principles, see\n[Notifications](/design/ui/mobile/guides/home-screen/notifications).\n**Figure 1.** CallStyle template for incoming and ongoing calls.\n\nThe required actions are passed as intents, such as `hangupIntent` and\n`answerIntent` in the following sections. Each of these are a reference to a\ntoken maintained by the system. The token is a lightweight object that\ncan be passed between different apps and processes. The system is\nresponsible for managing the lifetime of the token and ensuring that the\n`PendingIntent` is usable even if the app that created it is no longer\nrunning. When you give another app a `PendingIntent`, you are granting\nit the permission to perform the operation specified, such as decline or answer.\nThis permission is granted even if the app that created the intent\nis not currently running. For more information, see the reference documentation\nfor [`PendingIntent`](/reference/android/app/PendingIntent).\n\nStarting in Android 14 (API level 34), you can configure call notifications\nto be non-dismissible. To do so, use `CallStyle` notifications with the\n[`Notification.FLAG_ONGOING_EVENT`](/reference/android/app/Notification#FLAG_ONGOING_EVENT) through\n[`Notification.Builder#setOngoing(true)`](/reference/android/app/Notification.Builder#setOngoing(boolean)).\n\nThe following are examples of using various methods with the `CallStyle`\nnotification. \n\n### Kotlin\n\n```kotlin\n// Create a new call, setting the user as the caller.\nval incomingCaller = Person.Builder()\n .setName(\"Jane Doe\")\n .setImportant(true)\n .build()\n```\n\n### Java\n\n```java\n// Create a new call with the user as the caller.\nPerson incomingCaller = new Person.Builder()\n .setName(\"Jane Doe\")\n .setImportant(true)\n .build();\n```\n\nIncoming call\n-------------\n\nUse the `forIncomingCall()` method to create a call style notification for an\nincoming call. \n\n### Kotlin\n\n```kotlin\n// Create a call style notification for an incoming call.\nval builder = Notification.Builder(context, CHANNEL_ID)\n .setContentIntent(contentIntent)\n .setSmallIcon(smallIcon)\n .setStyle(\n Notification.CallStyle.forIncomingCall(caller, declineIntent, answerIntent))\n .addPerson(incomingCaller)\n```\n\n### Java\n\n```java\n// Create a call style notification for an incoming call.\nNotification.Builder builder = Notification.Builder(context, CHANNEL_ID)\n .setContentIntent(contentIntent)\n .setSmallIcon(smallIcon)\n .setStyle(\n Notification.CallStyle.forIncomingCall(caller, declineIntent, answerIntent))\n .addPerson(incomingCaller);\n```\n\nOngoing call\n------------\n\nUse the `forOngoingCall()` method to create a call style notification for an\nongoing call. \n\n### Kotlin\n\n```kotlin\n// Create a call style notification for an ongoing call.\nval builder = Notification.Builder(context, CHANNEL_ID)\n .setContentIntent(contentIntent)\n .setSmallIcon(smallIcon)\n .setStyle(\n Notification.CallStyle.forOngoingCall(caller, hangupIntent))\n .addPerson(second_caller)\n```\n\n### Java\n\n```java\n// Create a call style notification for an ongoing call.\nNotification.Builder builder = new Notification.Builder(context, CHANNEL_ID)\n .setContentIntent(contentIntent)\n .setSmallIcon(smallIcon)\n .setStyle(\n Notification.CallStyle.forOngoingCall(caller, hangupIntent))\n .addPerson(second_caller);\n```\n\nScreen a call\n-------------\n\nUse the `forScreeningCall()` method to create a call style notification for\nscreening a call. \n\n### Kotlin\n\n```kotlin\n// Create a call style notification for screening a call.\nval builder = Notification.Builder(context, CHANNEL_ID)\n .setContentIntent(contentIntent)\n .setSmallIcon(smallIcon)\n .setStyle(\n Notification.CallStyle.forScreeningCall(caller, hangupIntent, answerIntent))\n .addPerson(second_caller)\n```\n\n### Java\n\n```java\n// Create a call style notification for screening a call.\nNotification.Builder builder = new Notification.Builder(context, CHANNEL_ID)\n .setContentIntent(contentIntent)\n .setSmallIcon(smallIcon)\n .setStyle(\n Notification.CallStyle.forScreeningCall(caller, hangupIntent, answerIntent))\n .addPerson(second_caller);\n```\n\nProvide compatibility across more Android versions\n--------------------------------------------------\n\nAssociate `CallStyle` notifications on API versions 30 or earlier with a\nforeground service in order to assign them the high rank they are given in API\nlevel 31 or later. Additionally, `CallStyle` notifications on API version 30\nor earlier can achieve a similar ranking by marking the notification as\ncolorized, using the [`setColorized()`](/reference/android/app/Notification.Builder#setColorized(boolean)) method.\n\nUse the Telecom APIs with `CallStyle` notifications. For more information, see\n[Telecom framework overview](/guide/topics/connectivity/telecom)."]]