4

When I swipe up after the local notification comes, the application notifications don't appear on the screen for a while. What could be the reason for this? I've read something that when heads up notifications are swiped up, it sends a warning to the system to prevent heads up notifications for a certain period of time, but how can I prevent this? I don't have any problems getting notifications in my app other than that.


fun getChatChannels(): MutableList<NotificationChannel> {

    val chatChannels = mutableListOf<NotificationChannel>()

    val chatChannel = NotificationChannel(
        IM_CHANNEL_ID,
        Application.getString(R.string.chat_channel_name),
        NotificationManager.IMPORTANCE_HIGH
    )

    chatChannel.setShowBadge(false)
    chatChannel.group = MESSAGE_GROUP_ID

    chatChannels.add(chatChannel)

    return chatChannels }



    private fun getChannelList(): MutableList<NotificationChannel> {

    val channelList = mutableListOf<NotificationChannel>()
    channelList.addAll(getChatChannels())

    return channelList
    }


    fun createGroupsAndChannels() {

    // Create the NotificationChannel, but only on API 26+ because
    // the NotificationChannel class is new and not in the support library
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

        val notificationManager =
            Application.instance.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

        notificationManager.createNotificationChannelGroups(getGroupList())
        notificationManager.createNotificationChannels(getChannelList())
    }
    Log.d(TAG, "Channels and groups created")
     }
      fun showChatNotification(destinationAddress: String, messageId: String, message: String) {
     ThreadManager.createUITask {
            val name = if (domainContact != null) {
                "${domainContact.firstName} ${domainContact.lastName}"
            } else {
                destinationAddress
            }

            val notificationIntent = Intent(Application.instance, MainActivity::class.java)
            notificationIntent.putExtra(
                Application.getString(R.string.key_conversation_participant),
                destinationAddress
            )
            notificationIntent.flags = Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS

            val pendingIntent = PendingIntent.getActivity(
                Application.instance,
                destinationAddress.hashCode(),
                notificationIntent,
                PendingIntent.FLAG_UPDATE_CURRENT
            )
            val notificationId = UUID.randomUUID().hashCode()

            val builder = NotificationCompat.Builder(Application.instance, IM_CHANNEL_ID)
                .setSmallIcon(R.drawable.ic_notification_message)
                .setColor(ContextCompat.getColor(Application.instance, R.color.colorPrimary))
                .setContentTitle(name)
                .setContentText(message)
                .setStyle(
                    NotificationCompat.BigTextStyle() // Expandable-Collapsible notification
                        .bigText(message)
                )
                .setPriority(NotificationCompat.PRIORITY_HIGH)
                .setDefaults(NotificationCompat.DEFAULT_ALL)
                .setCategory(NotificationCompat.CATEGORY_MESSAGE)
                .setContentIntent(pendingIntent)
                .setVisibility(VISIBILITY_PUBLIC)
                .setAutoCancel(true)

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                builder.addAction(getChatNotificationReplyAction(destinationAddress, notificationId, messageId))
            }

            chatNotifications.add(mapOf(destinationAddress to notificationId))
            createNotifications(builder, notificationId)

            Log.d(TAG, "Chat notification created")
        } 


  private fun createNotifications(builder: NotificationCompat.Builder, notificationId: Int) {

        with(NotificationManagerCompat.from(Application.instance)) {
            notify(notificationId, builder.build())
        }
    }
Ece Ayvaz
  • 53
  • 4
  • did you find any solution for this or what are the document says the warning to the system? – Sattar Feb 27 '23 at 10:01

0 Answers0