지속적인 알람이나 수신 전화와 같은 특정 상황에서 앱이 급하게 사용자의 주의를 환기해야 할 수 있습니다. Android 9 (API 수준 28) 이하를 실행하는 기기를 타겟팅하는 앱에서는 앱이 백그라운드에 있는 동안 활동을 시작하여 이를 처리할 수 있습니다. 이 문서에서는 Android 10 (API 수준 29)부터 Android 13 (API 수준 33)까지 실행되는 기기에서 이 동작을 달성하는 방법을 보여줍니다.
기기에서 Android 13을 실행하는 경우 Request
permission 버튼을 탭하면 그림 2에 표시된 대화상자가 트리거됩니다.
그림 2. 알림 권한 요청을 위한 시스템 대화상자
사용자가 권한 요청을 수락하면 앱의 앱 정보 섹션이 그림 3과 같이 표시됩니다.
그림 3. 알림 권한이 부여되었습니다.
우선순위가 높은 알림 만들기
알림을 만들 때 설명형 제목과 메시지를 포함합니다.
다음 예에는 알림이 포함되어 있습니다.
Kotlin
privatefunshowNotification(){valnotificationManager=getSystemService(Context.NOTIFICATION_SERVICE)asNotificationManagervalnotificationBuilder=NotificationCompat.Builder(this,CHANNEL_ID).setSmallIcon(R.drawable.baseline_auto_awesome_24).setContentTitle("HIGH PRIORITY").setContentText("Check this dog puppy video NOW!").setPriority(NotificationCompat.PRIORITY_HIGH).setCategory(NotificationCompat.CATEGORY_RECOMMENDATION)notificationManager.notify(666,notificationBuilder.build())}
사용자에게 알림을 표시하면 사용자는 앱의 알림이나 리마인더를 승인 또는 거부할 수 있습니다. 예를 들어 사용자는 수신 전화를 수락하거나 거부할 수 있습니다.
수신 전화와 같은 지속적인 알림인 경우에는 알림을 포그라운드 서비스와 연결합니다. 다음 코드 스니펫은 포그라운드 서비스와 연결된 알림을 표시하는 방법을 보여줍니다.
Kotlin
// Provide a unique integer for the "notificationId" of each notification.startForeground(notificationId,notification)
Java
// Provide a unique integer for the "notificationId" of each notification.startForeground(notificationId,notification);
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-08-21(UTC)
[null,null,["최종 업데이트: 2025-08-21(UTC)"],[],[],null,["# Display time-sensitive notifications\n\nYour app might need to get the user's attention urgently in certain situations,\nsuch as an ongoing alarm or an incoming call. In apps targeting devices that run\nAndroid 9 (API level 28) or earlier, you might handle this by launching an\nactivity while the app is in the background. This document shows how to achieve\nthis behavior on devices running Android 10 (API level 29) to\nAndroid 13 (API level 33).\n\nAdd the POST_NOTIFICATIONS permission\n-------------------------------------\n\nStarting in Android 13, add the following line to your\n`AndroidManifest.xml` file: \n\n```xml\n\u003cmanifest ...\u003e\n \u003cuses-permission android:name=\"android.permission.POST_NOTIFICATIONS\"/\u003e\n \u003capplication ...\u003e\n ...\n \u003c/application\u003e\n\u003c/manifest\u003e\n```\n\nOnce you have this, you can create a notification channel.\n\nCreate a notification channel\n-----------------------------\n\nCreate a notification channel to properly display your notifications and let the\nuser manage notifications in the app settings. For more information about\nnotification channels, see [Create and manage notification\nchannels](/develop/ui/views/notifications/channels).\n\nCreate your notification channels in your `Application` class's\n[`onCreate`](/reference/android/app/Application#onCreate()) method: \n\n### Kotlin\n\n```kotlin\nclass DACapp : Application() {\n override fun onCreate() {\n super.onCreate()\n val channel = NotificationChannel(\n CHANNEL_ID,\n \"High priority notifications\",\n NotificationManager.IMPORTANCE_HIGH\n )\n\n val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager\n notificationManager.createNotificationChannel(channel)\n }\n}\n```\n\nWhen the user runs your app for the first time, they see something like figure 1\nin your app's **App info** system screen:\n**Figure 1.** Notifications section in the **App\nInfo** screen of the app's system settings.\n\nManage notifications permissions\n--------------------------------\n\nStarting in Android 13, request notification permissions before\nyou show notifications to users.\n\nThe minimum implementation looks like this: \n\n### Kotlin\n\n```kotlin\nval permissionLauncher = rememberLauncherForActivityResult(\n contract = ActivityResultContracts.RequestPermission(),\n onResult = { hasNotificationPermission = it }\n)\n...\nButton(\n onClick = {\n if (!hasNotificationPermission) {\n if (Build.VERSION.SDK_INT \u003e= Build.VERSION_CODES.TIRAMISU) {\n permissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)\n }\n }\n },\n) {\n Text(text = \"Request permission\")\n}\n```\n\nIf your device is running Android 13, tapping the `Request\npermission` button triggers the dialog shown in figure 2:\n**Figure 2.** System dialog for the notification permission request.\n\nIf the user accepts the permission request, the app's **App info** section looks\nlike figure 3:\n**Figure 3.** Notification permissions granted. **Experimental:** See the Accompanist [Jetpack Compose\n| Permissions](https://google.github.io/accompanist/permissions/) library for experimental permission management.\n\nCreate a high-priority notification\n-----------------------------------\n\nWhen creating the notification, include a descriptive title and message.\n\nThe following example contains a notification: \n\n### Kotlin\n\n```kotlin\nprivate fun showNotification() {\n val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager\n\n val notificationBuilder =\n NotificationCompat.Builder(this, CHANNEL_ID)\n .setSmallIcon(R.drawable.baseline_auto_awesome_24)\n .setContentTitle(\"HIGH PRIORITY\")\n .setContentText(\"Check this dog puppy video NOW!\")\n .setPriority(NotificationCompat.PRIORITY_HIGH)\n .setCategory(NotificationCompat.CATEGORY_RECOMMENDATION)\n\n notificationManager.notify(666, notificationBuilder.build())\n}\n```\n\nDisplay the notification to the user\n------------------------------------\n\nCalling the `showNotification()` function triggers the notification as follows: \n\n### Kotlin\n\n```kotlin\nButton(onClick = { showNotification() }) {\n Text(text = \"Show notification\")\n}\n```\n\nThe notification in this example looks like figure 4:\n**Figure 4.** A high-priority notification.\n\nOngoing notification\n--------------------\n\nWhen you display your notification to the user, they can acknowledge or dismiss\nyour app's alert or reminder. For example, the user can accept or reject an\nincoming phone call.\n| **Note:** While the user is using the device, the system UI might display a heads-up notification instead of launching your full-screen intent.\n\nIf your notification is an ongoing one, such as an incoming phone call,\nassociate the notification with a [foreground\nservice](/guide/components/services#Foreground). The following code snippet\nshows how to display a notification associated with a foreground service: \n\n### Kotlin\n\n```kotlin\n// Provide a unique integer for the \"notificationId\" of each notification.\nstartForeground(notificationId, notification)\n```\n\n### Java\n\n```java\n// Provide a unique integer for the \"notificationId\" of each notification.\nstartForeground(notificationId, notification);\n```"]]