Kotlin-删除后再次出现通知

时间:2019-12-16 13:12:37

标签: kotlin google-cloud-firestore android-notifications

我当前正在将通知放入我的android应用中。我在Firestore中使用Kotlin。

我遇到的问题是,通知会根据数据库中的更新正确显示(很好!)

不正确的是,每次我打开应用程序并导航到写入通知的布局时,Firestore会重新运行数据库查询并再次弹出通知。现在在Firebase中,它没有执行此操作,因为我假设它正在检查数据更改,但是Firestore没有此功能。解决方法是什么?

我的通知代码是

docref.collection("winning_bid").whereEqualTo("seller_id",userid).addSnapshotListener{ value,task->

        if(value!=null){

            for(document in value!!){

                val currentseller_id = document.getString("seller_id")
                val deal_num = document.getLong("deal_num")!!

                if(userid == currentseller_id){

                    WinningBidNotificationChannel()

                    val CHANNEL_ID = "Winning Bid"

                    val intent = Intent(this, Mydeals_seller::class.java).apply {
                        flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
                    }

                    val pendingIntent = PendingIntent.getActivity(this,0,intent,0)

                    val builder = NotificationCompat.Builder(this,CHANNEL_ID)
                        .setSmallIcon(R.drawable.notificationicon)
                        .setContentTitle("Test Winning Bid")
                        .setContentText("Your bid has been selected as the leading bid")
                        .setStyle(
                            NotificationCompat.BigTextStyle()
                                .bigText("Your bid has been selected as the leading bid for Deal #${deal_num}"))
                        .setPriority(NotificationCompat.PRIORITY_HIGH)
                        .setContentIntent(pendingIntent)
                        .setChannelId(CHANNEL_ID)
                        .setAutoCancel(true)
                        .build()


                    with(NotificationManagerCompat.from(this)){

                        notify(0,builder)
                    }
                }
            }
        }
    }

如何在每次导航至此页面时不弹出通知,但在关闭应用程序后仍在后台弹出通知?

0 个答案:

没有答案