From 5a733b3a45d9c1b3ee79e448f9456845067911b6 Mon Sep 17 00:00:00 2001 From: jaeyoungkim Date: Mon, 22 Aug 2022 00:00:16 +0900 Subject: [PATCH] =?UTF-8?q?FCM=20Foreground=EC=97=90=EC=84=9C=20notificati?= =?UTF-8?q?on=EC=9D=B4=20=EC=83=9D=EC=84=B1=EB=90=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EB=8A=94=20=EC=9D=B4=EC=8A=88=20=EC=88=98=EC=A0=95=20=EB=B0=8F?= =?UTF-8?q?=20Android=2012=EC=9D=B4=EC=83=81=20=EB=B6=80=ED=84=B0=20Pendin?= =?UTF-8?q?g=20Intent=20Flag=20FLAG=5FIMMUTABLE=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=ED=95=B4=EC=95=BC=ED=95=98=EA=B8=B0=20=EB=95=8C=EB=AC=B8?= =?UTF-8?q?=EC=97=90=20=EC=B6=94=EA=B0=80=ED=95=98=EB=8A=94=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/FairerFirebaseMessagingService.kt | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/depromeet/housekeeper/service/FairerFirebaseMessagingService.kt b/app/src/main/java/com/depromeet/housekeeper/service/FairerFirebaseMessagingService.kt index 2e4b73b7..f2c4876d 100644 --- a/app/src/main/java/com/depromeet/housekeeper/service/FairerFirebaseMessagingService.kt +++ b/app/src/main/java/com/depromeet/housekeeper/service/FairerFirebaseMessagingService.kt @@ -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 @@ -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) } } @@ -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)