我尝试将fcm数据插入到Room数据库中,但是没有插入, 这是我在FirebaseMessagingService中尝试的代码
class NotificationService : FirebaseMessagingService() {
lateinit var db: NotificationDao
override fun onMessageReceived(remoteMessage: RemoteMessage) {
db = PrefDatabase.getInstance(applicationContext).NotificationDao() // getInstance is a companion object fun in PrefDatabase
if (remoteMessage.notification != null) {
showNotification(remoteMessage)
}
private fun showNotification(remoteMessage: RemoteMessage) {
........
.....
//Saving
Thread {
val notifi =Notifi(remoteMessage.notification.title, remoteMessage.notification.body)
db.insertNotification(notifi)
}.start()
}
}
}