如何将FCM插入房间数据库?

时间:2019-10-26 16:30:30

标签: android firebase-cloud-messaging android-room

我尝试将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()
 }
}


}

0 个答案:

没有答案