Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FCM Foreground에서 notification이 생성되지 않는 이슈 수정 #132

Merged
merged 1 commit into from
Aug 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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