Skip to content

Commit

Permalink
Merge pull request #132 from depromeet/fix/fcm
Browse files Browse the repository at this point in the history
FCM Foreground에서 notification이 생성되지 않는 이슈 수정
  • Loading branch information
JY-Dev authored Aug 21, 2022
2 parents 0f41d56 + 5a733b3 commit af24ee4
Showing 1 changed file with 5 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.NotificationManager.IMPORTANCE_HIGH
import android.app.PendingIntent
import android.app.PendingIntent.FLAG_IMMUTABLE
import android.app.PendingIntent.FLAG_ONE_SHOT
import android.content.Context
import android.content.Intent
Expand Down Expand Up @@ -35,20 +36,9 @@ class FairerFirebaseMessagingService: FirebaseMessagingService() {
@Override
override fun onMessageReceived(message: RemoteMessage) {
super.onMessageReceived(message)
Timber.tag(TAG_FCM).d("From: ${message.from}")
if (message.data.isNotEmpty()) {

// payload : 전송된 데이터
Timber.tag(TAG_FCM).d("Message data payload: ${message.data}")

val title = message.data["title"]
val body = message.data["message"]

showNotification(messageTitle = title, messageBody = body)
}

Timber.tag(TAG_FCM).d("Message: $message")
message.notification?.let {
Timber.tag(TAG_FCM).d("Message Notification Body: ${it.body}")
showNotification(messageTitle = it.title, messageBody = it.body)
}
}

Expand All @@ -62,7 +52,8 @@ class FairerFirebaseMessagingService: FirebaseMessagingService() {
val intent = Intent(this, HouseKeeperActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
}
val pendingIntent = PendingIntent.getActivity(this, notificationID, intent, FLAG_ONE_SHOT)
val pendingIntentFlag = if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) FLAG_IMMUTABLE or FLAG_ONE_SHOT else FLAG_ONE_SHOT
val pendingIntent = PendingIntent.getActivity(this, notificationID, intent, pendingIntentFlag)
val soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)

val notificationBuilder = NotificationCompat.Builder(this, CHANNEL_ID)
Expand Down

0 comments on commit af24ee4

Please sign in to comment.