통화 앱의 통화 스타일 알림 만들기

Android 12.0 (API 수준 31) 이상에서 시스템은 통화 알림을 다른 유형의 알림과 구별하기 위해 CallStyle 알림 템플릿을 제공합니다. 수신 또는 진행 중인 전화 알림을 만들려면 이 템플릿을 사용하세요. 템플릿은 발신자 정보와 전화 수락 또는 거부와 같은 필수 작업이 포함된 대형 알림을 지원합니다.

수신 전화와 진행 중인 전화는 우선순위가 높은 이벤트이므로 이러한 알림은 알림 창에서 가장 높은 우선순위를 받습니다. 또한 이 순위를 통해 시스템은 우선순위가 지정된 통화를 다른 기기로 전달할 수 있습니다.

CallStyle 알림 템플릿에는 다음과 같은 필수 작업이 포함되어 있습니다.

  • 수신 전화를 받기 또는 거부합니다.
  • 진행 중인 통화는 전화를 끊습니다.
  • 통화 선택을 위해 받기 또는 전화 끊기를 탭합니다.

이 스타일의 작업은 버튼으로 표시되며 시스템에서 적절한 아이콘과 텍스트를 자동으로 추가합니다. 버튼에 대한 수동 라벨 지정은 지원되지 않습니다. 알림 디자인 원칙에 관한 자세한 내용은 알림을 참고하세요.

라벨이 지정된 버튼이 있는 통화 스타일 알림
그림 1. 수신 및 진행 중인 통화를 위한 CallStyle 템플릿

다음 섹션에서는 필요한 작업이 hangupIntentanswerIntent과 같은 인텐트로 전달됩니다. 이는 각각 시스템에서 유지관리하는 토큰의 참조입니다. 토큰은 경량의 객체로 여러 앱과 프로세스 간에 전달할 수 있습니다. 시스템은 토큰의 전체 기간을 관리하고 PendingIntent를 생성한 앱이 더 이상 실행 중이 아닌 경우에도 사용할 수 있도록 하는 일을 담당합니다. 다른 앱에 PendingIntent을 부여하면 거부 또는 응답과 같은 지정된 작업을 실행할 수 있는 권한이 부여됩니다. 이 권한은 인텐트를 만든 앱이 현재 실행 중이 아닌 경우에도 부여됩니다. 자세한 내용은 PendingIntent 참조 문서를 확인하세요.

Android 14 (API 수준 34)부터 통화 알림을 닫을 수 없도록 구성할 수 있습니다. 이렇게 하려면 Notification.FLAG_ONGOING_EVENT에서 Notification.Builder#setOngoing(true)를 통해 CallStyle 알림을 사용합니다.

다음은 CallStlye 알림과 함께 다양한 메서드를 사용하는 예입니다.

Kotlin

// Create a new call, setting the user as the caller.
val incomingCaller = Person.Builder()
    .setName("Jane Doe")
    .setImportant(true)
    .build()

Java

// Create a new call with the user as the caller.
Person incomingCaller = new Person.Builder()
    .setName("Jane Doe")
    .setImportant(true)
    .build();

수신 전화

forIncomingCall() 메서드를 사용하여 수신 전화의 통화 스타일 알림을 만듭니다.

Kotlin

// Create a call style notification for an incoming call.
val builder = 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.Builder builder = 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.
val builder = 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.Builder builder = new Notification.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.
val builder = 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.Builder builder = new Notification.Builder(context, CHANNEL_ID)
    .setContentIntent(contentIntent)
    .setSmallIcon(smallIcon)
    .setStyle(
        Notification.CallStyle.forScreeningCall(caller, hangupIntent, answerIntent))
    .addPerson(second_caller);

더 많은 Android 버전에서 호환성 제공

API 버전 30 이하에서 CallStyle 알림을 포그라운드 서비스와 연결하여 API 수준 31 이상에서 부여된 높은 순위를 할당합니다. 또한 API 버전 30 이하에서 CallStyle 알림은 setColorized() 메서드를 사용하여 알림을 색상으로 표시하면 비슷한 순위를 얻을 수 있습니다.

CallStyle 알림과 함께 Telecom API를 사용합니다. 자세한 내용은 텔레콤 프레임워크 개요를 참고하세요.