Skip to content

Commit

Permalink
Merge pull request droidknights#145 from droidknights/feature/z0/push…
Browse files Browse the repository at this point in the history
…_server

fcm token 서버에 저장
  • Loading branch information
Jiyoung9310 authored Sep 2, 2020
2 parents 3de7343 + d49f4b8 commit 6126878
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,21 +1,46 @@
package com.droidknights.app2020.push

import android.app.*
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Build
import android.util.Log
import androidx.core.app.NotificationCompat
import com.droidknights.app2020.R
import com.droidknights.app2020.ui.MainActivity
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import dagger.hilt.android.AndroidEntryPoint
import timber.log.Timber
import javax.inject.Inject

@AndroidEntryPoint
class MyFirebaseMessagingService : FirebaseMessagingService() {

@Inject
lateinit var firestore: FirebaseFirestore

override fun onNewToken(s: String) {
super.onNewToken(s)
Timber.d("FCM_NEW_TOKEN $s")

val data = hashMapOf(
"token" to s
)

firestore.collection("FcmToken")
.add(data)
.addOnSuccessListener { documentReference ->
Log.d("MessagingService", "DocumentSnapshot written with ID: ${documentReference.id}")
}
.addOnFailureListener { e ->
Log.w("MessagingService", "Error adding document", e)
}

}

override fun onMessageReceived(remoteMessage: RemoteMessage) {
Expand Down

0 comments on commit 6126878

Please sign in to comment.