如何保持通知图标删除抬头通知?

时间:2020-06-29 08:42:36

标签: android kotlin android-notifications

我使用平视通知。如果我不使用setTimeoutAfter()方法,则此抬头通知将永久保留。所以我用了这种方法。但是问题在于该方法还删除了通知图标。我只想保留3秒后移除抬头通知的通知图标。如何解决呢?我尝试使用notificationManager.cancel(id),但此结果与使用setTimeoutAfter()相同。

    override fun onMessageReceived(remoteMessage: RemoteMessage) {

        val bitmap = Glide.with(this).asBitmap().load(remoteMessage.data["imageURL"]).submit().get()

        val messageBody = remoteMessage.data["body"]
        val messageTitle = remoteMessage.data["title"]
        val intent = Intent(this, LoginActivity::class.java)
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
        val pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT)
        val channelId = "$packageName.channel"
        val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
        val inboxStyle = NotificationCompat.InboxStyle()
        val style = NotificationCompat.BigTextStyle()
        style.bigText(messageBody)

        Log.d("TAG", "channelId : $channelId")


        val notificationBuilder = NotificationCompat.Builder(this,channelId)
            .setSmallIcon(R.drawable.haiilogo)
            .setContentTitle(messageTitle)
            .setContentText(messageBody)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setLargeIcon(bitmap)
            .setColor(resources.getColor(R.color.colorPrimary))
            .setDefaults(NotificationCompat.DEFAULT_ALL)
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setStyle(style)
            .setLights(Color.BLUE,1,1)
            .setFullScreenIntent(pendingIntent,true)


        val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
            val channelName ="ScheduleChannel"

            val channel = NotificationChannel(channelId,channelName, NotificationManager.IMPORTANCE_HIGH)
            channel.enableLights(true)
            channel.lightColor= 0x00FFFF
            channel.setShowBadge(false)
            notificationManager.createNotificationChannel(channel)
        }

        notificationManager.notify(1000,notificationBuilder.build())
    
    }

0 个答案:

没有答案
相关问题