Я пытаюсь создать простую Android программу (в Kotlin), которая должна отображать уведомление через 10 секунд. Я вижу уведомление после открытия быстрых настроек и прокрутки вниз, но оно не появляется вверху автоматически.
Это соответствующий код:
lateinit var notificationManager: NotificationManager
lateinit var notificationChannel: NotificationChannel
lateinit var builder: Notification.Builder
val channelId = "com.example.vicky.notificationexample"
val description = "Test notification"
class MyIntentService : IntentService("MyIntentService") {
override fun onHandleIntent(intent: Intent?) {
notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val intent = Intent (this, LauncherActivity::class.java)
val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
notificationChannel = NotificationChannel(channelId, description, NotificationManager.IMPORTANCE_HIGH)
notificationChannel.enableLights(true)
notificationChannel.lightColor = Color.GREEN
notificationChannel.enableVibration(true)
notificationManager.createNotificationChannel(notificationChannel)
builder = Notification.Builder(this, channelId)
.setContentTitle("Some Title")
.setContentText("Some text")
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setLargeIcon(BitmapFactory.decodeResource(this.resources, R.mipmap.ic_launcher_round))
.setContentIntent(pendingIntent)
Thread.sleep(10000)
notificationManager.notify(1234, builder.build())
}
}