지속적인 알람이나 수신 전화와 같은 특별한 경우에 앱이 급하게 사용자의 주의를 환기해야 할 수 있습니다. 이전에 앱이 백그라운드에 있는 동안 활동을 시작하여 이 목적으로 앱을 구성했을 수 있습니다.
Android 10(API 레벨 29) 이상을 실행하는 기기에서 유사한 동작을 제공하려면 이 가이드에 설명된 단계를 완료합니다.
우선순위가 높은 알림 만들기
알림을 만들 때 설명형 제목과 메시지가 포함되도록 해야 합니다. 선택적으로 전체 화면 인텐트를 제공할 수도 있습니다.
알림 예는 다음 코드 스니펫에 표시됩니다.
Kotlin
val fullScreenIntent = Intent(this, CallActivity::class.java) val fullScreenPendingIntent = PendingIntent.getActivity(this, 0, fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT) val notificationBuilder = NotificationCompat.Builder(this, CHANNEL_ID) .setSmallIcon(R.drawable.notification_icon) .setContentTitle("Incoming call") .setContentText("(919) 555-1234") .setPriority(NotificationCompat.PRIORITY_HIGH) .setCategory(NotificationCompat.CATEGORY_CALL) // Use a full-screen intent only for the highest-priority alerts where you // have an associated activity that you would like to launch after the user // interacts with the notification. Also, if your app targets Android 10 // or higher, you need to request the USE_FULL_SCREEN_INTENT permission in // order for the platform to invoke this notification. .setFullScreenIntent(fullScreenPendingIntent, true) val incomingCallNotification = notificationBuilder.build()
자바
Intent fullScreenIntent = new Intent(this, CallActivity.class); PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(this, 0, fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, CHANNEL_ID) .setSmallIcon(R.drawable.notification_icon) .setContentTitle("Incoming call") .setContentText("(919) 555-1234") .setPriority(NotificationCompat.PRIORITY_HIGH) .setCategory(NotificationCompat.CATEGORY_CALL) // Use a full-screen intent only for the highest-priority alerts where you // have an associated activity that you would like to launch after the user // interacts with the notification. Also, if your app targets Android 10 // or higher, you need to request the USE_FULL_SCREEN_INTENT permission in // order for the platform to invoke this notification. .setFullScreenIntent(fullScreenPendingIntent, true); Notification incomingCallNotification = notificationBuilder.build();
사용자에게 알림 표시
사용자에게 알림을 표시하면 사용자는 앱의 알림이나 리마인더를 승인 또는 거부할지 여부를 선택할 수 있습니다. 예를 들어, 사용자는 수신 전화를 허용하거나 거부할지 여부를 선택할 수 있습니다.
수신 전화와 같은 지속적인 알림인 경우에는 알림을 포그라운드 서비스와 연결합니다. 다음 코드 스니펫은 포그라운드 서비스와 연결된 알림을 표시하는 방법을 보여 줍니다.
Kotlin
// Provide a unique integer for the "notificationId" of each notification. startForeground(notificationId, notification)
자바
// Provide a unique integer for the "notificationId" of each notification. startForeground(notificationId, notification);