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())}
[null,null,["最后更新时间 (UTC):2025-08-21。"],[],[],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```"]]